-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
32 lines (24 loc) · 867 Bytes
/
Copy pathmiddleware.js
File metadata and controls
32 lines (24 loc) · 867 Bytes
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
import { NextResponse } from 'next/server'
import { cookies } from 'next/headers'
// This function can be marked `async` if using `await` inside
export function middleware(request) {
const listCookies = cookies()
const logged = listCookies.has("logged") ? listCookies.get("logged").value : null
if (request.nextUrl.pathname.startsWith('/cuenta')) {
return logged == "true"
? NextResponse.redirect(new URL('/', request.url))
: NextResponse.next()
}
if (logged == "true") return NextResponse.next()
// NO SE ENCUENTRA UNA SESIÓN ACTIVA, por lo que no tendra un token valido
return NextResponse.redirect(new URL('/cuenta', request.url))
}
export const config = {
matcher: [
"/cuenta",
"/notas", "/tareas/(.*)",
"/api/tasks", "/api/tasks/(.*)",
"/api/notes", "/api/notes/(.*)"
],
}
// '/horarios', '/calendario'