diff --git a/apps/dashboard/src/actions/sign-out-action.ts b/apps/dashboard/src/actions/sign-out-action.ts index 27dd8e42ce..03c415ac1b 100644 --- a/apps/dashboard/src/actions/sign-out-action.ts +++ b/apps/dashboard/src/actions/sign-out-action.ts @@ -9,7 +9,9 @@ export async function signOutAction() { data: { session }, } = await supabase.auth.getSession(); - await supabase.auth.signOut(); + await supabase.auth.signOut({ + scope: "local", + }); revalidateTag(`user_${session.user.id}`); } diff --git a/apps/dashboard/src/app/api/auth/callback/route.ts b/apps/dashboard/src/app/api/auth/callback/route.ts index 8565b6b62c..e8363e10ca 100644 --- a/apps/dashboard/src/app/api/auth/callback/route.ts +++ b/apps/dashboard/src/app/api/auth/callback/route.ts @@ -23,5 +23,9 @@ export async function GET(req: NextRequest) { await supabase.auth.exchangeCodeForSession(code); } - return NextResponse.redirect(`${requestUrl.origin}/${returnTo}`); + if (returnTo) { + return NextResponse.redirect(`${requestUrl.origin}/${returnTo}`); + } + + return NextResponse.redirect(requestUrl.origin); } diff --git a/apps/dashboard/src/components/google-sign-in.tsx b/apps/dashboard/src/components/google-sign-in.tsx index eae4f3b36e..0ab8053ad7 100644 --- a/apps/dashboard/src/components/google-sign-in.tsx +++ b/apps/dashboard/src/components/google-sign-in.tsx @@ -11,10 +11,18 @@ export function GoogleSignIn() { const returnTo = searchParams.get("return_to"); const handleSignIn = async () => { + const redirectTo = new URL("/api/auth/callback", location.origin); + + if (returnTo) { + redirectTo.searchParams.append("return_to", returnTo); + } + + redirectTo.searchParams.append("provider", "google"); + await supabase.auth.signInWithOAuth({ provider: "google", options: { - redirectTo: `${location.origin}/api/auth/callback?return_to=${returnTo}&provider=google`, + redirectTo: redirectTo.toString(), }, }); }; diff --git a/apps/dashboard/src/components/sign-out.tsx b/apps/dashboard/src/components/sign-out.tsx index 5fd2aa51c4..fb0842e24d 100644 --- a/apps/dashboard/src/components/sign-out.tsx +++ b/apps/dashboard/src/components/sign-out.tsx @@ -15,7 +15,7 @@ export function SignOut() { const handleSignOut = async () => { setLoading(true); signOutAction(); - router.replace("/"); + router.refresh(); }; return ( diff --git a/apps/dashboard/src/middleware.ts b/apps/dashboard/src/middleware.ts index 13358f4b9e..786160720b 100644 --- a/apps/dashboard/src/middleware.ts +++ b/apps/dashboard/src/middleware.ts @@ -17,9 +17,9 @@ export async function middleware(request: NextRequest) { if (!data.session && request.nextUrl.pathname !== "/") { const url = new URL("/", request.url); - const encodedSearchParams = encodeURIComponent( - `${request.nextUrl.pathname.substring(1)}${request.nextUrl.search}` - ); + const encodedSearchParams = `${request.nextUrl.pathname.substring(1)}${ + request.nextUrl.search + }`; url.searchParams.append("return_to", encodedSearchParams);