Supabase proper redirect
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// app/auth/callback/route.ts
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { createClient } from "@/lib/supabase/server";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const code = req.nextUrl.searchParams.get("code");
|
||||
|
||||
if (!code) {
|
||||
return NextResponse.json({ error: "code param required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const supabase = await createClient();
|
||||
|
||||
const { error } = await supabase.auth.exchangeCodeForSession(code);
|
||||
|
||||
if (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
|
||||
return NextResponse.redirect(new URL("/runs", req.url));
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import { signInWithGitHub } from "@/modules/account/actions";
|
||||
|
||||
export default function ContinueWith() {
|
||||
const continueWithGithub = () => {
|
||||
signInWithGitHub();
|
||||
signInWithGitHub(window.location.origin);
|
||||
};
|
||||
const continueWithGoogle = () => {};
|
||||
|
||||
|
||||
@@ -24,3 +24,25 @@ export async function createClient() {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function createClientApi() {
|
||||
const cookieStore = await cookies();
|
||||
|
||||
return createServerClient(
|
||||
process.env.SUPABASE_URL!,
|
||||
process.env.SUPABASE_SECRET_KEY!,
|
||||
{
|
||||
cookies: {
|
||||
get(name: string) {
|
||||
return cookieStore.get(name)?.value;
|
||||
},
|
||||
set(name: string, value: string, options: CookieOptions) {
|
||||
cookieStore.set(name, value, options);
|
||||
},
|
||||
remove(name: string, options: CookieOptions) {
|
||||
cookieStore.set(name, "", options);
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
"use server";
|
||||
|
||||
import * as Core from "./core";
|
||||
import { createClient } from "@/lib/supabase";
|
||||
import { createClient } from "@/lib/supabase/server";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function signInWithGitHub() {
|
||||
export async function signInWithGitHub(origin: string) {
|
||||
const supabase = await createClient();
|
||||
|
||||
const { data, error } = await supabase.auth.signInWithOAuth({
|
||||
provider: "github",
|
||||
options: {
|
||||
redirectTo: `${origin}/api/auth/callback`,
|
||||
},
|
||||
});
|
||||
|
||||
if (error) {
|
||||
|
||||
@@ -66,3 +66,19 @@ export async function getSession(
|
||||
|
||||
return [user, profile];
|
||||
}
|
||||
|
||||
export async function signInWithGitHub(supabase: SupabaseClient) {
|
||||
const { data, error } = await supabase.auth.signInWithOAuth({
|
||||
provider: "github",
|
||||
options: {
|
||||
redirectTo: `/auth/callback`,
|
||||
},
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
return data.url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user