WIP 61eabc4e
Steve · 2024-09-20 06:57 2 file(s) · +28 −1
src/components/SignInButton.tsx +1 −1
5 5
		await supabase.auth.signInWithOAuth({
6 6
			provider: "github",
7 7
			options: {
8 -
				redirectTo: "https://stevedylan.dev/auth/callback",
8 +
				redirectTo: "https://stevedylan.dev/api/auth/callback",
9 9
			},
10 10
		});
11 11
	}
src/pages/api/auth/callback.ts (added) +27 −0
1 +
import type { APIRoute } from "astro";
2 +
import { supabase } from "../../../lib/supabase";
3 +
4 +
export const GET: APIRoute = async ({ url, cookies, redirect }) => {
5 +
	const authCode = url.searchParams.get("code");
6 +
7 +
	if (!authCode) {
8 +
		return new Response("No code provided", { status: 400 });
9 +
	}
10 +
11 +
	const { data, error } = await supabase.auth.exchangeCodeForSession(authCode);
12 +
13 +
	if (error) {
14 +
		return new Response(error.message, { status: 500 });
15 +
	}
16 +
17 +
	const { access_token, refresh_token } = data.session;
18 +
19 +
	cookies.set("sb-access-token", access_token, {
20 +
		path: "/",
21 +
	});
22 +
	cookies.set("sb-refresh-token", refresh_token, {
23 +
		path: "/",
24 +
	});
25 +
26 +
	return redirect("/dashboard");
27 +
};