mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-06-03 19:25:19 +02:00
allow redirect after auth
This commit is contained in:
parent
da58903f67
commit
46bbe4c189
1 changed files with 10 additions and 1 deletions
|
|
@ -6,6 +6,15 @@ const corsOptions = {
|
||||||
'Access-Control-Allow-Headers': 'Content-Type, x-client-id, Authorization',
|
'Access-Control-Allow-Headers': 'Content-Type, x-client-id, Authorization',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function authCheck(request: NextRequest) {
|
||||||
|
const session = await auth0.getSession(request);
|
||||||
|
const loginUrl = new URL('/auth/login', request.url);
|
||||||
|
loginUrl.searchParams.set('returnTo', request.nextUrl.pathname + request.nextUrl.search);
|
||||||
|
if (!session) {
|
||||||
|
return NextResponse.redirect(loginUrl);
|
||||||
|
}
|
||||||
|
return auth0.middleware(request);
|
||||||
|
}
|
||||||
|
|
||||||
export async function middleware(request: NextRequest, event: NextFetchEvent) {
|
export async function middleware(request: NextRequest, event: NextFetchEvent) {
|
||||||
// Check if the request path starts with /api/auth/
|
// Check if the request path starts with /api/auth/
|
||||||
|
|
@ -42,7 +51,7 @@ export async function middleware(request: NextRequest, event: NextFetchEvent) {
|
||||||
request.nextUrl.pathname.startsWith('/onboarding')) {
|
request.nextUrl.pathname.startsWith('/onboarding')) {
|
||||||
// Skip auth check if USE_AUTH is not enabled
|
// Skip auth check if USE_AUTH is not enabled
|
||||||
if (process.env.USE_AUTH === 'true') {
|
if (process.env.USE_AUTH === 'true') {
|
||||||
return await auth0.middleware(request);
|
return await authCheck(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue