WIP
61eabc4e
2 file(s) · +28 −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 | } |
| 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 | + | }; |