import type { RequestHandler } from '@sveltejs/kit';
import { setSteamIdCookie, verifySteamOpenIDResponse } from '$lib/server/steam';

export const GET: RequestHandler = async ({ url, cookies }) => {
  const sp = url.searchParams;
  const steamId = await verifySteamOpenIDResponse(sp);
  if (!steamId) {
    return new Response('Steam verification failed', { status: 400 });
  }
  setSteamIdCookie(cookies, steamId);
  const redirectTo = sp.get('redirect_uri') ?? '/';
  return new Response(null, { status: 302, headers: { Location: redirectTo } });
};


