transfer Ownership
This commit is contained in:
parent
8f23a688cb
commit
0fb7a563d0
10 changed files with 195 additions and 10 deletions
|
@ -22,3 +22,16 @@ export async function abilityAndNavUpdate(to: any, from: any, next: any) {
|
|||
next(false);
|
||||
}
|
||||
}
|
||||
|
||||
export async function isOwner(to: any, from: any, next: any) {
|
||||
NProgress.start();
|
||||
const ability = useAbilityStore();
|
||||
|
||||
if (ability.isOwner) {
|
||||
NProgress.done();
|
||||
next();
|
||||
} else {
|
||||
NProgress.done();
|
||||
next(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ export async function isAuthenticated(to: any, from: any, next: any) {
|
|||
});
|
||||
}
|
||||
|
||||
export async function isAuthenticatedPromise(): Promise<Payload> {
|
||||
export async function isAuthenticatedPromise(forceRefresh: boolean = false): Promise<Payload> {
|
||||
return new Promise<Payload>(async (resolve, reject) => {
|
||||
const auth = useAuthStore();
|
||||
const account = useAccountStore();
|
||||
|
@ -55,7 +55,7 @@ export async function isAuthenticatedPromise(): Promise<Payload> {
|
|||
// check jwt expiry
|
||||
const exp = decoded.exp ?? 0;
|
||||
const correctedLocalTime = new Date().getTime();
|
||||
if (exp < Math.floor(correctedLocalTime / 1000)) {
|
||||
if (exp < Math.floor(correctedLocalTime / 1000) || forceRefresh) {
|
||||
await refreshToken()
|
||||
.then(() => {
|
||||
console.log("fetched new token");
|
|
@ -1,7 +1,7 @@
|
|||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import Login from "@/views/Login.vue";
|
||||
|
||||
import { isAuthenticated } from "./authGuards";
|
||||
import { isAuthenticated } from "./authGuard";
|
||||
import { loadAccountData } from "./accountGuard";
|
||||
import { isSetup } from "./setupGuard";
|
||||
import { abilityAndNavUpdate } from "./adminGuard";
|
||||
|
@ -476,6 +476,11 @@ const router = createRouter({
|
|||
name: "account-permission",
|
||||
component: () => import("@/views/account/Permission.vue"),
|
||||
},
|
||||
{
|
||||
path: "administration",
|
||||
name: "account-administration",
|
||||
component: () => import("@/views/account/Administration.vue"),
|
||||
},
|
||||
{
|
||||
path: ":pathMatch(.*)*",
|
||||
name: "account-404",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue