-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
33 lines (25 loc) · 1.05 KB
/
middleware.ts
File metadata and controls
33 lines (25 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { NextRequest, NextResponse } from 'next/server';
// TODO: Ver como importar paquetes externos aqui
// import { jwt } from './services';
export async function middleware ( req:NextRequest ) {
const token = req.cookies.get('token') || '';
try {
// TODO: Temporal solution. remplace by
// await jwt.isValidToken( token );
if( token.length <= 10 )
throw new Error();
} catch (error) {
return NextResponse.redirect(new URL( `/auth/login?p=${req.nextUrl.pathname}`, req.nextUrl.origin ))
}
// TODO: Validar que el usuario tenga el rol necesario para acceder a la ruta
// const validRoles = ['admin', 'super-admin', 'SEO'];
// if( req.nextUrl.pathname === '/admin') {
// if( !validRoles.includes( useRole ) )
// return NextResponse.redirect(new URL( `/`, req.nextUrl.origin ))
// }
return NextResponse.next();
// TODO: Validar las rutas del admin endpoint (VIDEO 10, Seccion 21)
}
export const config = {
matcher: ['/checkout/:path', '/admin']
}