feat: review backend and frontend
- update to the latest version of Java/SpringBoot - update to the latest version NuxtJS - add account/password update - add account creation - add account password reset - add bundle to regroup questions and add default questions on user creation - add bundle creation
This commit is contained in:
34
frontend/middleware/auth.global.ts
Normal file
34
frontend/middleware/auth.global.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import {useAuthStore} from "~/store/auth";
|
||||
|
||||
const publicUrl = [
|
||||
"index",
|
||||
"login",
|
||||
"account-password-reset",
|
||||
"account-password-confirm-reset",
|
||||
"account-create",
|
||||
"cgu"
|
||||
]
|
||||
|
||||
export default defineNuxtRouteMiddleware((to) => {
|
||||
const {authenticated} = storeToRefs(useAuthStore()); // make authenticated state reactive
|
||||
// const token = useCookie('token'); // get token from cookies
|
||||
const store = useAuthStore();
|
||||
|
||||
// if (token.value) {
|
||||
// // check if value exists
|
||||
// authenticated.value = true; // update the state to authenticated
|
||||
// }
|
||||
|
||||
// if token exists and url is /login redirect to homepage
|
||||
if (store.isLoggedIn && !store.isSessionExpired && to?.name === 'login') {
|
||||
return navigateTo('/bundle');
|
||||
}
|
||||
|
||||
console.info(`${store.isLoggedIn}, ${store.isSessionExpired}`)
|
||||
|
||||
// if token doesn't exist redirect to log in if not in public URL
|
||||
if ((!store.isLoggedIn || store.isSessionExpired) && !publicUrl.includes(to?.name)) {
|
||||
abortNavigation();
|
||||
return navigateTo('/login');
|
||||
}
|
||||
});
|
14
frontend/middleware/redirect.ts
Normal file
14
frontend/middleware/redirect.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
// import { Context } from '@nuxt/types'
|
||||
|
||||
// export default function (context: Context) {
|
||||
// context.redirect(301, '/redirect');
|
||||
// }
|
||||
|
||||
// export default function ({ $auth, redirect }) {
|
||||
// if (process.client) {
|
||||
// if (!$auth.loggedIn || !$auth.user.role.includes('admin')) {
|
||||
// redirect('/admin/login')
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// https://stackoverflow.com/questions/64433369/how-to-auto-redirect-to-login-after-an-unauthorized-api-request-ex-when-token
|
Reference in New Issue
Block a user