-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { createClient } from '@ultra-reporter/supabase/server'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams, origin } = new URL(request.url); | ||
const code = searchParams.get('code'); | ||
// if "next" is in param, use it as the redirect URL | ||
const next = searchParams.get('next') ?? '/'; | ||
|
||
if (code) { | ||
const supabase = await createClient(); | ||
const { error } = await supabase.auth.exchangeCodeForSession(code); | ||
if (!error) { | ||
const forwardedHost = request.headers.get('x-forwarded-host'); // original origin before load balancer | ||
const isLocalEnv = process.env.NODE_ENV === 'development'; | ||
if (isLocalEnv) { | ||
// we can be sure that there is no load balancer in between, so no need to watch for X-Forwarded-Host | ||
return NextResponse.redirect(`${origin}${next}`); | ||
} else if (forwardedHost) { | ||
return NextResponse.redirect(`https://${forwardedHost}${next}`); | ||
} else { | ||
return NextResponse.redirect(`${origin}${next}`); | ||
} | ||
} | ||
} | ||
|
||
// return the user to an error page with instructions | ||
return NextResponse.redirect(`${origin}/auth/auth-code-error`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { logger } from '@ultra-reporter/logger'; | ||
import { createClient } from '@ultra-reporter/supabase/server'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function POST(req: Request) { | ||
const supabase = await createClient(); | ||
|
||
const origin = req.headers.get('origin'); | ||
|
||
const { provider } = await req.json(); | ||
const { error, data } = await supabase.auth.signInWithOAuth({ | ||
provider, | ||
options: { | ||
redirectTo: `${origin}/auth/callback`, | ||
}, | ||
}); | ||
|
||
if (error) { | ||
logger.error('Sign up failed', error); | ||
return new NextResponse('Error while signing up', { | ||
status: 500, | ||
}); | ||
} | ||
|
||
const { | ||
data: { user }, | ||
} = await supabase.auth.getUser(); | ||
|
||
if (!user) { | ||
logger.error('User not found'); | ||
return new NextResponse('Error while signing up', { | ||
status: 500, | ||
}); | ||
} | ||
|
||
logger.info('Sign up successful', data); | ||
return NextResponse.json(user, { | ||
status: 201, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,6 @@ | |
"react-dom": "^19.0" | ||
}, | ||
"dependencies": { | ||
"flagsmith": "^8.0.1" | ||
"flagsmith": "^8.0.2" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.