diff --git a/apps/dashboard/src/app/api/auth/callback/route.ts b/apps/dashboard/src/app/api/auth/callback/route.ts index 0ef9ea12b1..8565b6b62c 100644 --- a/apps/dashboard/src/app/api/auth/callback/route.ts +++ b/apps/dashboard/src/app/api/auth/callback/route.ts @@ -11,6 +11,7 @@ export async function GET(req: NextRequest) { const cookieStore = cookies(); const requestUrl = new URL(req.url); const code = requestUrl.searchParams.get("code"); + const returnTo = requestUrl.searchParams.get("return_to"); const provider = requestUrl.searchParams.get("provider"); if (provider) { @@ -22,5 +23,5 @@ export async function GET(req: NextRequest) { await supabase.auth.exchangeCodeForSession(code); } - return NextResponse.redirect(requestUrl.origin); + return NextResponse.redirect(`${requestUrl.origin}/${returnTo}`); } diff --git a/apps/dashboard/src/components/google-sign-in.tsx b/apps/dashboard/src/components/google-sign-in.tsx index 60d5caaf49..eae4f3b36e 100644 --- a/apps/dashboard/src/components/google-sign-in.tsx +++ b/apps/dashboard/src/components/google-sign-in.tsx @@ -3,15 +3,18 @@ import { createClient } from "@midday/supabase/client"; import { Button } from "@midday/ui/button"; import { Icons } from "@midday/ui/icons"; +import { useSearchParams } from "next/navigation"; export function GoogleSignIn() { const supabase = createClient(); + const searchParams = useSearchParams(); + const returnTo = searchParams.get("return_to"); const handleSignIn = async () => { await supabase.auth.signInWithOAuth({ provider: "google", options: { - redirectTo: `${location.origin}/api/auth/callback?provider=google`, + redirectTo: `${location.origin}/api/auth/callback?return_to=${returnTo}&provider=google`, }, }); }; diff --git a/apps/dashboard/src/components/sign-out.tsx b/apps/dashboard/src/components/sign-out.tsx index fb0842e24d..5fd2aa51c4 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.refresh(); + router.replace("/"); }; return ( diff --git a/apps/dashboard/src/middleware.ts b/apps/dashboard/src/middleware.ts index d567da3bf8..13358f4b9e 100644 --- a/apps/dashboard/src/middleware.ts +++ b/apps/dashboard/src/middleware.ts @@ -16,7 +16,14 @@ export async function middleware(request: NextRequest) { const { data } = await supabase.auth.getSession(); if (!data.session && request.nextUrl.pathname !== "/") { - return NextResponse.redirect(new URL("/", request.url)); + const url = new URL("/", request.url); + const encodedSearchParams = encodeURIComponent( + `${request.nextUrl.pathname.substring(1)}${request.nextUrl.search}` + ); + + url.searchParams.append("return_to", encodedSearchParams); + + return NextResponse.redirect(url); } if ( diff --git a/apps/website/public/overview-light.png b/apps/website/public/overview-light.png index 2adda009cf..9df6362f90 100644 Binary files a/apps/website/public/overview-light.png and b/apps/website/public/overview-light.png differ diff --git a/apps/website/src/components/startpage.tsx b/apps/website/src/components/startpage.tsx index 041f21d06b..88680766bd 100644 --- a/apps/website/src/components/startpage.tsx +++ b/apps/website/src/components/startpage.tsx @@ -105,40 +105,52 @@ export function StartPage() {