fix: bugs fixed, we still have the 404 error
This commit is contained in:
parent
8024b8070b
commit
b5637e4552
24
front/MyINPulse-front/src/services/tools.ts
Normal file
24
front/MyINPulse-front/src/services/tools.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
import { store } from "@/main";
|
||||
|
||||
type TokenPayload = {
|
||||
realm_access?: {
|
||||
roles?: string[];
|
||||
};
|
||||
};
|
||||
|
||||
function isAdmin(): boolean {
|
||||
if (store.authenticated && store.user.token) {
|
||||
const decoded = jwtDecode<TokenPayload>(store.user.token);
|
||||
const roles = decoded.realm_access?.roles || [];
|
||||
if (roles.includes("MyINPulse-admin")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export { isAdmin };
|
Loading…
x
Reference in New Issue
Block a user