Update various configuration files, components, and assets; enhance notification system and API endpoints; improve documentation and styles across the application.
This commit is contained in:
26
middleware/auth.js
Normal file
26
middleware/auth.js
Normal file
@@ -0,0 +1,26 @@
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
const { $swal } = useNuxtApp();
|
||||
|
||||
if (process.client) {
|
||||
// Validate every request to every page
|
||||
const { data: validateUser } = await useFetch("/api/auth/validate", {
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
// If user is not logged in, redirect to logout page
|
||||
if (validateUser.value.statusCode === 401) {
|
||||
$swal
|
||||
.fire({
|
||||
title: "Session Expired",
|
||||
text: "Your session has expired. Please login again.",
|
||||
icon: "warning",
|
||||
confirmButtonText: "OK",
|
||||
})
|
||||
.then(() => {
|
||||
return window.location.replace("/logout");
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user