mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-02-27 15:24:42 +08:00
feat: admin api cookie
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
|
||||
export async function middleware(request: NextRequest) {
|
||||
const { pathname } = request.nextUrl;
|
||||
|
||||
@@ -94,28 +96,6 @@ async function verifySignature(
|
||||
}
|
||||
}
|
||||
|
||||
// 从cookie获取认证信息
|
||||
function getAuthInfoFromCookie(request: NextRequest): {
|
||||
password?: string;
|
||||
username?: string;
|
||||
signature?: string;
|
||||
timestamp?: number;
|
||||
} | null {
|
||||
const authCookie = request.cookies.get('auth');
|
||||
|
||||
if (!authCookie) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const decoded = decodeURIComponent(authCookie.value);
|
||||
const authData = JSON.parse(decoded);
|
||||
return authData;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 重定向到登录页面
|
||||
function redirectToLogin(request: NextRequest, pathname: string): NextResponse {
|
||||
const loginUrl = new URL('/login', request.url);
|
||||
|
||||
Reference in New Issue
Block a user