You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I try to use vue router middleware for guarding routes that needs user to be authenticated. I try to get isPending value, but it's always return true. How to await keycloak initialization finished then guard the route app?
here's my main.ts code:
import{createApp}from"vue";import{createRouter,createWebHistory}from"vue-router";importAppfrom"./App.vue";importroutesfrom"./routes";import"./assets/css/index.css";import{vueKeycloak}from"@baloise/vue-keycloak";import{createPinia}from"pinia";constapp=createApp(App);constrouter=createRouter({history: createWebHistory(),routes: routes});app.use(createPinia());app.use(vueKeycloak,{initOptions: {checkLoginIframe: false,onLoad: "check-sso",silentCheckSsoRedirectUri:
window.location.origin+"/assets/silent-check-sso.html",},config: {url: import.meta.env.VITE_SSO_URL,realm: import.meta.env.VITE_SSO_REALM,clientId: import.meta.env.VITE_SSO_CLIENT_ID,},});console.log('keycloak initialized. run application.')console.log('START: using router')app.use(router);console.log('END: using router')app.mount("#app");
here's my auth guard route middleware code (for now):
import{getToken,useKeycloak}from"@baloise/vue-keycloak";const{ keycloak, isPending, isAuthenticated }=useKeycloak();constauthGuard=async(to: any,from: any)=>{console.log(isPending.value);try{console.log("is pending: ",isPending.value);if(!isPending.value){console.log(`is pending is false.`);console.log(isAuthenticated.value);consttoken=awaitgetToken();if(!isAuthenticated.value){alert("Sesi anda sudah habis. Silakan untuk login kembali.");return"/";}}}catch(error){alert(error);return"/";}};exportdefaultauthGuard;
The text was updated successfully, but these errors were encountered:
I try to use vue router middleware for guarding routes that needs user to be authenticated. I try to get
isPending
value, but it's always return true. How to await keycloak initialization finished then guard the route app?here's my
main.ts
code:here's my auth guard route middleware code (for now):
The text was updated successfully, but these errors were encountered: