rp/src/routes/auth/discord/+server.ts

15 lines
659 B
TypeScript

import { redirect, type RequestHandler } from '@sveltejs/kit';
export const GET: RequestHandler = async ({ url }) => {
// The redirect target after a successful login.
// Default to root; can be overridden via ?next= for deep links.
const next = url.searchParams.get('next');
const safeNext = next && next.startsWith('/') && !next.startsWith('//') ? next : '/';
const stateRedirect = encodeURIComponent(safeNext);
// Lazy import to avoid loading the OAuth module unless we need it.
const { buildAuthorizeUrl } = await import('$lib/server/auth');
const authorizeUrl = buildAuthorizeUrl(stateRedirect);
throw redirect(302, authorizeUrl);
};