File tree 5 files changed +25
-6
lines changed
5 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -5,10 +5,20 @@ import { redirect } from "next/navigation";
5
5
6
6
import { createClient } from "@/utils/supabase/server" ;
7
7
8
- export async function signInWithGoogle ( ) {
8
+ export async function signInWithGoogle ( { nextUrl } : { nextUrl ?: string } = { } ) {
9
9
const supabase = await createClient ( ) ;
10
10
const origin = ( await headers ( ) ) . get ( "origin" ) ;
11
- const redirectTo = `${ origin } /auth/callback` ;
11
+
12
+ // Redirect config
13
+ const baseUrl = `${ origin } /auth/callback` ;
14
+ const searchParams = new URLSearchParams ( ) ;
15
+
16
+ if ( nextUrl ) {
17
+ searchParams . append ( "next_url" , nextUrl ) ;
18
+ }
19
+
20
+ const queryString = searchParams . toString ( ) ;
21
+ const redirectTo = queryString ? `${ baseUrl } ?${ queryString } ` : baseUrl ;
12
22
13
23
const { data, error } = await supabase . auth . signInWithOAuth ( {
14
24
options : {
Original file line number Diff line number Diff line change 1
1
"use client" ;
2
2
3
3
import Image from "next/image" ;
4
+ import { use } from "react" ;
4
5
5
6
import { Button } from "@/components/ui/button" ;
6
7
import { signInWithGoogle } from "@/actions/auth" ;
7
8
8
- export default function Login ( ) {
9
+ type SearchParams = Promise < { [ key : string ] : string | string [ ] | undefined } > ;
10
+
11
+ export default function SignInPage ( props : { searchParams : SearchParams } ) {
12
+ const searchParams = use ( props . searchParams ) ;
13
+ const redirect = searchParams . redirect as string | undefined ;
14
+
9
15
const handleSignIn = async ( ) => {
10
- await signInWithGoogle ( ) ;
16
+ await signInWithGoogle ( { nextUrl : redirect } ) ;
11
17
} ;
12
18
13
19
return (
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { createClient } from "@/utils/supabase/server";
5
5
export async function GET ( request : Request ) {
6
6
const { searchParams, origin } = new URL ( request . url ) ;
7
7
const code = searchParams . get ( "code" ) ;
8
- const next = searchParams . get ( "next " ) ?? "/dashboard " ;
8
+ const next = searchParams . get ( "next_url " ) ?? "/get-started " ;
9
9
10
10
if ( code ) {
11
11
const supabase = await createClient ( ) ;
Original file line number Diff line number Diff line change 6
6
"dev" : " next dev --turbo" ,
7
7
"format" : " prettier . --write" ,
8
8
"format:check" : " prettier . --check" ,
9
+ "generate:types" : " supabase gen types typescript --local > ./types/database.ts" ,
9
10
"build" : " next build" ,
10
11
"start" : " next start" ,
11
12
"lint" : " next lint"
Original file line number Diff line number Diff line change @@ -40,7 +40,9 @@ export const updateSession = async (request: NextRequest) => {
40
40
) ;
41
41
42
42
if ( isProtectedRoute && user . error ) {
43
- return NextResponse . redirect ( new URL ( "/sign-in" , request . url ) ) ;
43
+ const redirectUrl = new URL ( "/sign-in" , request . url ) ;
44
+ redirectUrl . searchParams . set ( "redirect" , request . nextUrl . pathname ) ;
45
+ return NextResponse . redirect ( redirectUrl ) ;
44
46
}
45
47
46
48
if ( request . nextUrl . pathname === "/" && ! user . error ) {
You can’t perform that action at this time.
0 commit comments