mirror of
https://github.com/Kizuren/uLinkShortener.git
synced 2026-01-09 07:57:57 +01:00
Biome format
This commit is contained in:
parent
47969209eb
commit
8729e57def
85 changed files with 2467 additions and 1983 deletions
35
src/proxy.ts
35
src/proxy.ts
|
|
@ -5,36 +5,37 @@ import type { NextRequest } from 'next/server';
|
|||
export async function proxy(request: NextRequest) {
|
||||
const path = request.nextUrl.pathname;
|
||||
const response = NextResponse.next();
|
||||
|
||||
|
||||
try {
|
||||
if (path === '/dashboard' ||
|
||||
path === '/admin' ||
|
||||
path.startsWith('/api/link/') ||
|
||||
path.startsWith('/dashboard/') ||
|
||||
path.startsWith('/admin/')) {
|
||||
|
||||
const token = await getToken({
|
||||
if (
|
||||
path === '/dashboard' ||
|
||||
path === '/admin' ||
|
||||
path.startsWith('/api/link/') ||
|
||||
path.startsWith('/dashboard/') ||
|
||||
path.startsWith('/admin/')
|
||||
) {
|
||||
const token = await getToken({
|
||||
req: request,
|
||||
secret: process.env.NEXTAUTH_SECRET || 'fallback-secret-for-testing'
|
||||
secret: process.env.NEXTAUTH_SECRET || 'fallback-secret-for-testing',
|
||||
});
|
||||
|
||||
|
||||
// Not authenticated
|
||||
if (!token) {
|
||||
return NextResponse.redirect(new URL('/', request.url));
|
||||
}
|
||||
|
||||
|
||||
// Check token expiration
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
if (token.exp && (token.exp as number) < now) {
|
||||
return NextResponse.redirect(new URL('/api/auth/signout?callbackUrl=/', request.url));
|
||||
}
|
||||
|
||||
|
||||
// Check admin access
|
||||
if ((path === '/admin' || path.startsWith('/admin/')) && !token.isAdmin) {
|
||||
return NextResponse.redirect(new URL('/dashboard', request.url));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('Middleware error:', error);
|
||||
|
|
@ -46,10 +47,10 @@ export async function proxy(request: NextRequest) {
|
|||
export const config = {
|
||||
matcher: [
|
||||
'/dashboard',
|
||||
'/dashboard/:path*',
|
||||
'/dashboard/:path*',
|
||||
'/admin',
|
||||
'/admin/:path*',
|
||||
'/api/link/:path*',
|
||||
'/api/auth/sessions/:path*'
|
||||
]
|
||||
};
|
||||
'/api/auth/sessions/:path*',
|
||||
],
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue