-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
23 lines (19 loc) · 771 Bytes
/
Copy pathmiddleware.ts
File metadata and controls
23 lines (19 loc) · 771 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 } from 'next/server';
import type { NextRequest } from 'next/server';
import { getKindeServerSession } from '@kinde-oss/kinde-auth-nextjs/server';
export async function middleware(request: NextRequest) {
// Await the result of getKindeServerSession() to get the session
const session = await getKindeServerSession();
// Check if the session exists and the user is authenticated
if (!session?.isAuthenticated) {
return NextResponse.redirect(
new URL('/api/auth/login?post_login_redirect_url=/dashboard', request.url)
);
}
// Continue with the request if the user is authenticated
return NextResponse.next();
}
// Configuration for matching the "/dashboard" path
export const config = {
matcher: '/dashboard',
};