integrate login page wih api and keycloak

This commit is contained in:
Yusron alamsyah
2026-03-31 11:11:39 +07:00
parent acf491f8aa
commit d438fb0f5f
68 changed files with 1213 additions and 212 deletions
+24
View File
@@ -0,0 +1,24 @@
// middleware/auth.ts
import { useAuth } from '~/composables/useAuth';
export default defineNuxtRouteMiddleware(async (to) => {
// This middleware should only run on the client-side after the initial server-side render.
if (process.server) {
return;
}
const { isLoggedIn, fetchUserSession } = useAuth();
// Initial check
if (!isLoggedIn.value) {
await fetchUserSession();
}
// List of public routes that don't require authentication
const publicRoutes = ['/auth/login', '/auth/register'];
// If the route is not public and the user is not logged in, redirect to login
if (!publicRoutes.includes(to.path) && !isLoggedIn.value) {
return navigateTo('/auth/login');
}
});