-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
23 lines (20 loc) · 779 Bytes
/
middleware.ts
File metadata and controls
23 lines (20 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { NextResponse, type NextRequest } from 'next/server';
export async function middleware(request: NextRequest) {
const cookie = request.cookies;
// Literally primative, but we can do more logic later for requests to
// reroute if user_id isnt actually associated with anything.
// We dont realllly care if they exist
const nextUrl = request.nextUrl;
console.log(nextUrl.pathname);
if (cookie.has('user_id')) {
if (nextUrl.pathname === '/event') {
return NextResponse.redirect(new URL('/event/list', request.url));
}
return;
}
// Not associated with a user, so bring them back to the earlier page
return NextResponse.redirect(new URL('/event/login', request.url));
}
export const config = {
matcher: ['/event/(.*)', '/event/'],
};