chore: migrate to composition API and auth0-spa

This commit is contained in:
2020-01-21 15:51:51 +01:00
parent 565a3aa66e
commit e6c87e2f46
44 changed files with 2489 additions and 1585 deletions
-30
View File
@@ -1,30 +0,0 @@
import auth from '~/utils/auth';
// do not add trailing slashes to the excluded paths.
const excludedPaths = ['', '/authorize', '/logout'];
// This function is not SSR-compatible, and works since our code currently only runs on the client.
export default function ({ isHMR, route }) {
// If middleware is called from hot module replacement, ignore it
if (isHMR) {
return;
}
// support both trailing slash and non-trailing slash so it works the same
// when hosted from s3 and not.
let path = route.path;
if (path.endsWith('/')) {
path = path.slice(0, -1);
}
if (!excludedPaths.includes(path)) {
if (auth.isExpired()) {
// if the auth has just expired - try to log in silently.
auth.triggerSilentLogin({ returnUrl: route.fullPath });
}
else if (!auth.isAuthenticated()) {
// otherwise, if the user is not authenticated, trigger a full login.
auth.triggerLogin({ returnUrl: route.fullPath });
}
}
}