Skip to content

Commit

Permalink
Theme
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Dec 2, 2023
1 parent b83d00f commit 41d8e9e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
4 changes: 3 additions & 1 deletion apps/dashboard/src/actions/sign-out-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
6 changes: 5 additions & 1 deletion apps/dashboard/src/app/api/auth/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 9 additions & 1 deletion apps/dashboard/src/components/google-sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
});
};
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/components/sign-out.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function SignOut() {
const handleSignOut = async () => {
setLoading(true);
signOutAction();
router.replace("/");
router.refresh();
};

return (
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 41d8e9e

Please sign in to comment.