feat: setup protected routes
This commit is contained in:
parent
77ef7038d2
commit
d43c0f78b4
2 changed files with 17 additions and 1 deletions
|
@ -3,4 +3,9 @@ import Authentik from 'next-auth/providers/authentik';
|
||||||
|
|
||||||
export const { handlers, signIn, signOut, auth } = NextAuth({
|
export const { handlers, signIn, signOut, auth } = NextAuth({
|
||||||
providers: [Authentik],
|
providers: [Authentik],
|
||||||
|
callbacks: {
|
||||||
|
authorized: async ({ auth }) => {
|
||||||
|
return !!auth;
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -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).*)'],
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue