front_foundation #9

Closed
mohamed_maoulainine wants to merge 181 commits from front_foundation into main
Showing only changes of commit 32de0d6ca8 - Show all commits

View File

@ -5,6 +5,7 @@ import { createPinia } from "pinia";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
import keycloakService from "./services/keycloak";
import { type AuthStore, useAuthStore } from "@/stores/authStore.ts";
import { jwtDecode } from "jwt-decode";
let store: AuthStore;
@ -28,6 +29,32 @@ keycloakService.CallInit(() => {
}
});
adnane marked this conversation as resolved Outdated
Outdated
Review

We can't let this kind of comments

We can't let this kind of comments
type TokenPayload = {
realm_access?: {
Outdated
Review

remove this if it's commented.

remove this if it's commented.
roles?: string[];
};
};
function isAdmin(){
if (store.authenticated && store.user.token) {
try {
const decoded = jwtDecode<TokenPayload>(store.user.token);
const roles = decoded.realm_access?.roles || [];
if (roles.includes("MyINPulse-admin")) {
return true;
} else {
return false;
}
} catch (err) {
console.error("Failed to decode token", err);
}
}
}
// this shit made by me so i can run the canva vue app
//createApp(App).use(router).mount('#app');