feat: setup protected routes

This commit is contained in:
Dominik 2025-04-19 01:25:23 +02:00 committed by SomeCodecat
parent 77ef7038d2
commit d43c0f78b4
2 changed files with 17 additions and 1 deletions

View file

@ -3,4 +3,9 @@ import Authentik from 'next-auth/providers/authentik';
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [Authentik],
callbacks: {
authorized: async ({ auth }) => {
return !!auth;
},
},
});

View file

@ -1 +1,12 @@
export { auth as middleware } from '@/auth';
import { auth } from '@/auth';
export default auth((req) => {
if (!req.auth && req.nextUrl.pathname !== '/login') {
const newUrl = new URL('/login', req.nextUrl.origin);
return Response.redirect(newUrl);
}
});
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};