refacto time check

This commit is contained in:
OxSaitama 2023-09-25 09:30:22 +02:00
parent 9308554419
commit 84dc3a7ffd

View File

@ -19,7 +19,9 @@ export async function middleware(request: NextRequest) {
// If JWT expired, redirect to login page
const token = userDecodedToken ?? customerDecodedToken;
const now = Math.floor(Date.now() / 1000);
const currentDate = new Date();
const time = currentDate.getTime();
const now = Math.floor(time / 1000);
if (token.exp < now) {
console.log('token expired')
return NextResponse.redirect(new URL("/login", request.url));