mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Dashboard work and related
This commit is contained in:
parent
7bda2b1763
commit
b230a73a6f
44 changed files with 637 additions and 272 deletions
|
@ -1,15 +1,25 @@
|
|||
import { NavigationGuard } from "vue-router";
|
||||
import { RootStore } from "./store";
|
||||
|
||||
export const authGuard: NavigationGuard = async (to, from, next) => {
|
||||
if (RootStore.state.auth.apiKey) return next(); // We have an API key -> authenticated
|
||||
if (RootStore.state.auth.loadedInitialAuth) return next("/login"); // No API key and initial auth data was already loaded -> not authenticated
|
||||
const isAuthenticated = async () => {
|
||||
if (RootStore.state.auth.apiKey) return true; // We have an API key -> authenticated
|
||||
if (RootStore.state.auth.loadedInitialAuth) return false; // No API key and initial auth data was already loaded -> not authenticated
|
||||
await RootStore.dispatch("auth/loadInitialAuth"); // Initial auth data wasn't loaded yet (per above check) -> load it now
|
||||
if (RootStore.state.auth.apiKey) return next();
|
||||
next("/login"); // Still no API key -> not authenticated
|
||||
if (RootStore.state.auth.apiKey) return true;
|
||||
return false; // Still no API key -> not authenticated
|
||||
};
|
||||
|
||||
export const authGuard: NavigationGuard = async (to, from, next) => {
|
||||
if (await isAuthenticated()) return next();
|
||||
next("/");
|
||||
};
|
||||
|
||||
export const loginCallbackGuard: NavigationGuard = async (to, from, next) => {
|
||||
await RootStore.dispatch("auth/setApiKey", to.query.apiKey);
|
||||
next("/dashboard");
|
||||
};
|
||||
|
||||
export const authRedirectGuard: NavigationGuard = async (to, form, next) => {
|
||||
if (await isAuthenticated()) return next("/dashboard");
|
||||
window.location.href = `${process.env.API_URL}/auth/login`;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue