navigation permission and ability checker

This commit is contained in:
Julian Krauser 2024-08-26 17:56:07 +02:00
parent cb80771f7a
commit 35cba95887
6 changed files with 213 additions and 92 deletions

View file

@ -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);
}
});