navigation permission and ability checker
This commit is contained in:
parent
cb80771f7a
commit
35cba95887
6 changed files with 213 additions and 92 deletions
|
@ -4,6 +4,7 @@ import { useAccountStore } from "@/stores/account";
|
|||
import { jwtDecode, type JwtPayload } from "jwt-decode";
|
||||
import { refreshToken } from "../serverCom";
|
||||
import type { PermissionObject } from "../types/permissionTypes";
|
||||
import { useAbilityStore } from "../stores/ability";
|
||||
|
||||
export type Payload = JwtPayload & {
|
||||
userId: number;
|
||||
|
@ -37,6 +38,7 @@ export async function isAuthenticatedPromise(): Promise<Payload> {
|
|||
return new Promise<Payload>(async (resolve, reject) => {
|
||||
const auth = useAuthStore();
|
||||
const account = useAccountStore();
|
||||
const ability = useAbilityStore();
|
||||
let decoded: Payload | string = "";
|
||||
try {
|
||||
decoded = jwtDecode<Payload>(localStorage.getItem("accessToken") ?? "");
|
||||
|
@ -72,7 +74,8 @@ export async function isAuthenticatedPromise(): Promise<Payload> {
|
|||
}
|
||||
|
||||
auth.setSuccess();
|
||||
account.setAccountData(firstname, lastname, mail, username, permissions);
|
||||
account.setAccountData(firstname, lastname, mail, username);
|
||||
ability.setAbility(permissions);
|
||||
resolve(decoded);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue