MeetUp/src/middleware.ts
Maximilian Liebmann 8298dbba28
All checks were successful
container-scan / Container Scan (pull_request) Successful in 2m31s
docker-build / docker (pull_request) Successful in 7m43s
fix: update middleware to redirect authenticated users to home
Automatically redirectis authenticated users from root path ('/') to the '/home' page.
2025-05-11 12:21:02 +02:00

19 lines
537 B
TypeScript

import { auth } from '@/auth';
export default auth((req) => {
if (
!req.auth &&
req.nextUrl.pathname !== '/login' &&
process.env.MEETUP_SKIP_LOGIN !== 'true'
) {
const newUrl = new URL('/login', req.nextUrl.origin);
return Response.redirect(newUrl);
} else if (req.auth != null && req.nextUrl.pathname === '/') {
const newUrl = new URL('/home', req.nextUrl.origin);
return Response.redirect(newUrl);
}
});
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};