NORY-20: improve authentication middleware (#21)
This commit is contained in:
commit
1234766c6d
1 changed files with 12 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getFrontendApi } from 'ory/sdk/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { getFrontendApi } from '@/ory/sdk/server';
|
||||
|
||||
export async function middleware(request: NextRequest) {
|
||||
|
||||
|
@ -26,6 +26,17 @@ export async function middleware(request: NextRequest) {
|
|||
return NextResponse.redirect(url);
|
||||
}
|
||||
|
||||
if (session && request.nextUrl.pathname.startsWith('/flow')) {
|
||||
|
||||
console.log('SESSION EXISTS');
|
||||
|
||||
const returnTo = request.nextUrl.searchParams.get('return_to') ?? request.nextUrl.host;
|
||||
|
||||
console.log('REDIRECT TO', returnTo);
|
||||
|
||||
return NextResponse.redirect(returnTo);
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue