Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit21d112e

Browse files
committed
create callback api
1 parent293c2d9 commit21d112e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎app/auth/callback/route.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import{NextResponse}from'next/server'
2+
3+
import{createClient}from'@/lib/supabase/server'
4+
5+
exportasyncfunctionGET(request:Request){
6+
const{ searchParams, origin}=newURL(request.url)
7+
constcode=searchParams.get('code')
8+
letnext=searchParams.get('next')??'/'
9+
if(!next.startsWith('/')){
10+
next='/'
11+
}
12+
13+
if(code){
14+
constsupabase=awaitcreateClient()
15+
const{ error}=awaitsupabase.auth.exchangeCodeForSession(code)
16+
if(!error){
17+
constforwardedHost=request.headers.get('x-forwarded-host')
18+
constisLocalEnv=process.env.NODE_ENV==='development'
19+
if(isLocalEnv){
20+
returnNextResponse.redirect(`${origin}${next}`)
21+
}elseif(forwardedHost){
22+
returnNextResponse.redirect(`https://${forwardedHost}${next}`)
23+
}else{
24+
returnNextResponse.redirect(`${origin}${next}`)
25+
}
26+
}
27+
}
28+
29+
returnNextResponse.redirect(
30+
`${origin}/auth/error?error=An error occurred while signing in.`,
31+
)
32+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp