23 lines
743 B
TypeScript
23 lines
743 B
TypeScript
import { cookies } from 'next/headers';
|
|
import { NextResponse } from 'next/server';
|
|
|
|
import { getAuthService } from '../../../../lib/auth';
|
|
|
|
export async function GET(request: Request) {
|
|
const url = new URL(request.url);
|
|
const returnTo = url.searchParams.get('returnTo') ?? undefined;
|
|
|
|
const authService = getAuthService();
|
|
const { redirectUrl, state } = await authService.startIracingAuthRedirect(returnTo);
|
|
|
|
const cookieStore = await cookies();
|
|
cookieStore.set('gp_demo_auth_state', state, {
|
|
httpOnly: true,
|
|
sameSite: 'lax',
|
|
path: '/',
|
|
secure: process.env.NODE_ENV === 'production',
|
|
});
|
|
|
|
const absoluteRedirect = new URL(redirectUrl, url.origin).toString();
|
|
return NextResponse.redirect(absoluteRedirect);
|
|
} |