feat: minor format + upgrade
This commit is contained in:
@@ -4,43 +4,43 @@ import type { User } from "~/stores/user";
|
||||
const LOGIN_ROUTE = "/login";
|
||||
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
let session: string | null = null;
|
||||
let session: string | null = null;
|
||||
|
||||
// Not secured route// Recover user session
|
||||
if (
|
||||
to.path.startsWith("/favicon.ico") ||
|
||||
to.path.startsWith("/assets/") ||
|
||||
to.path.startsWith(LOGIN_ROUTE)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
// Not secured route// Recover user session
|
||||
if (
|
||||
to.path.startsWith("/favicon.ico") ||
|
||||
to.path.startsWith("/assets/") ||
|
||||
to.path.startsWith(LOGIN_ROUTE)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Recover user session
|
||||
// NOTE: using the sessionStorage will not allow the user to have multiple tabs, to communicate them one can use the
|
||||
// broadcast channel, although its not the safest way: https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API
|
||||
try {
|
||||
session = sessionStorage.getItem(
|
||||
USER_SESSION_STORAGE_KEY,
|
||||
);
|
||||
// Recover user session
|
||||
// NOTE: using the sessionStorage will not allow the user to have multiple tabs, to communicate them one can use the
|
||||
// broadcast channel, although its not the safest way: https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API
|
||||
try {
|
||||
session = sessionStorage.getItem(
|
||||
USER_SESSION_STORAGE_KEY,
|
||||
);
|
||||
|
||||
// Manage secured routes
|
||||
if (session) {
|
||||
const user = JSON.parse(session) as User;
|
||||
if (
|
||||
user.apiSession?.exp &&
|
||||
user.apiSession.exp > Date.now()
|
||||
) {
|
||||
// try refresh token if it exists
|
||||
// else just redirect to login
|
||||
return navigateTo(LOGIN_ROUTE);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
return navigateTo(LOGIN_ROUTE);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(">> [!] Not in client", e);
|
||||
}
|
||||
// Manage secured routes
|
||||
if (session) {
|
||||
const user = JSON.parse(session) as User;
|
||||
if (
|
||||
user.apiSession?.exp &&
|
||||
user.apiSession.exp > Date.now()
|
||||
) {
|
||||
// try refresh token if it exists
|
||||
// else just redirect to login
|
||||
return navigateTo(LOGIN_ROUTE);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
return navigateTo(LOGIN_ROUTE);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(">> [!] Not in client", e);
|
||||
}
|
||||
|
||||
console.log(">> Global Middleware from ", from.path);
|
||||
console.log(">> Global Middleware from ", from.path);
|
||||
});
|
||||
|
||||
4934
front-nuxt/package-lock.json
generated
4934
front-nuxt/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
4736
front/package-lock.json
generated
4736
front/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user