dev-audioprocessing/middleware/auth.ts

13 lines
494 B
TypeScript
Raw Normal View History

2023-03-05 16:37:21 +00:00
import {useUserStore} from '@/stores/user';
2023-03-05 19:53:06 +00:00
// @ts-ignore
export default defineNuxtRouteMiddleware(async ({store, redirect}) => {
const app = useNuxtApp();
const user = await useUserStore(app.$pinia);
2023-03-05 16:37:21 +00:00
const localePath = useLocalePath()
2023-03-05 19:53:06 +00:00
console.log(user.is_login);
2023-03-05 16:37:21 +00:00
// isAuthenticated() is an example method verifying if a user is authenticated
2023-03-05 19:53:06 +00:00
if (!user.is_login) {
console.log('User not logged in');
return navigateTo(localePath('/auth/login'));
2023-03-05 16:37:21 +00:00
}
})