Add support for auth0

This commit is contained in:
2023-01-24 19:55:16 -05:00
parent b9f008603a
commit 86ca9f1ecb
40 changed files with 8273 additions and 39304 deletions

View File

@@ -0,0 +1,28 @@
import {getInstance} from "@/plugins/auth0";
export const authGuard = (to, from, next) => {
const authService = getInstance();
const fn = () => {
// If the user is authenticated, continue with the route
if (authService.isAuthenticated) {
return next();
}
// Otherwise, log in
authService.loginWithRedirect({appState: {targetUrl: to.fullPath}});
};
// If loading has already finished, check our auth state using `fn()`
if (!authService.loading) {
return fn();
}
// Watch for the loading property to change before we check isAuthenticated
authService.$watch("loading", loading => {
if (loading === false) {
return fn();
}
});
};

View File

@@ -4,14 +4,29 @@ import StatsPage from "../views/StatsPage.vue"
import Configuration from "../views/Configuration.vue"
import SearchPage from "@/views/SearchPage.vue";
import FilePage from "@/views/FilePage.vue";
import {authGuard as auth0AuthGuard} from "@/router/auth0";
Vue.use(VueRouter)
let USE_AUTH0 = false
export function setUseAuth0(val) {
USE_AUTH0 = val;
}
const authGuard = (to, from, next) => {
if (USE_AUTH0) {
return auth0AuthGuard(to, from, next);
}
next();
}
const routes: Array<RouteConfig> = [
{
path: "/",
name: "SearchPage",
component: SearchPage
component: SearchPage,
beforeEnter: authGuard
},
{
path: "/stats",
@@ -34,7 +49,7 @@ const router = new VueRouter({
mode: "hash",
base: process.env.BASE_URL,
routes,
scrollBehavior (to, from, savedPosition) {
scrollBehavior(to, from, savedPosition) {
// return desired position
}
})