mirror of
https://codeberg.org/MarkusThielker/finances.git
synced 2025-07-02 03:29:17 +00:00
N-FIN-79: add auth0 sdk
This commit is contained in:
parent
39cd91a53a
commit
642d64ad5e
4 changed files with 152 additions and 31 deletions
3
src/app/api/auth/[auth0]/route.js
Normal file
3
src/app/api/auth/[auth0]/route.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { handleAuth } from '@auth0/nextjs-auth0';
|
||||
|
||||
export const GET = handleAuth();
|
|
@ -1,27 +1,3 @@
|
|||
import type { NextRequest } from 'next/server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { URL_AUTH, URL_HOME, URL_SIGN_IN } from './lib/constants';
|
||||
import { withMiddlewareAuthRequired } from '@auth0/nextjs-auth0/edge';
|
||||
|
||||
export async function middleware(request: NextRequest) {
|
||||
|
||||
// get session id from cookies
|
||||
const sessionId = request.cookies.get('auth_session')?.value ?? null;
|
||||
|
||||
// redirect to home if user is already authenticated
|
||||
if (request.nextUrl.pathname.startsWith(URL_AUTH) && sessionId) {
|
||||
return NextResponse.redirect(new URL(URL_HOME, request.url));
|
||||
}
|
||||
|
||||
// redirect to sign in if user is not authenticated
|
||||
if (!request.nextUrl.pathname.startsWith(URL_AUTH) && !sessionId) {
|
||||
return NextResponse.redirect(new URL(URL_SIGN_IN, request.url));
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
'/((?!api|_next/static|_next/image|favicon.ico).*)',
|
||||
],
|
||||
};
|
||||
export default withMiddlewareAuthRequired();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue