Lanyards is a dedicated profile for researchers, built on the AT Protocol.
1import { NextResponse } from 'next/server';
2import type { NextRequest } from 'next/server';
3
4export default function proxy(request: NextRequest) {
5 const sessionCookie = request.cookies.get('lanyard_session');
6 const isAuthPage = request.nextUrl.pathname.startsWith('/auth');
7 const isProtectedPage =
8 request.nextUrl.pathname.startsWith('/dashboard') ||
9 request.nextUrl.pathname.startsWith('/profile/edit');
10
11 // Redirect authenticated users away from auth page
12 if (isAuthPage && sessionCookie) {
13 return NextResponse.redirect(new URL('/dashboard', request.url));
14 }
15
16 // Redirect unauthenticated users to auth page
17 if (isProtectedPage && !sessionCookie) {
18 return NextResponse.redirect(new URL('/auth', request.url));
19 }
20
21 return NextResponse.next();
22}
23
24export const config = {
25 matcher: ['/auth', '/dashboard/:path*', '/profile/edit/:path*'],
26};