vue-auth0-plugin
vue-auth0-plugin copied to clipboard
Expand Documentation
More detailed and structured documentation. Maybe describe all available methods and properties.
Possibly with GitHub pages or as GitHub wiki?
@jnt0r , think more examples and an explanation of the flow in the README would be enough for most users. I'm happy to help you polish it if you write a draft. I just don't have enough understanding of how it all works to do it myself.
Does this look right to you or is there a better way of doing it?
// only authenticated users may access this Vue app
// the auth should apply to the entire site, not just select routes
router.beforeEach(async () => {
// an early exit if the user has been auth'd earlier
if (AuthenticationState && AuthenticationState.authenticated) {
return true;
}
// it could that the authentication is still in progress
// the problem with this call is that it never returns if authenticated
const isAuthed = await AuthenticationState.getAuthenticatedAsPromise();
// try to log in if not authenticated up to this point
if (!isAuthed) {
// this redirects to Auth0 login form, but sometimes it just logs me in
// even if I delete all auth0 cookies
auth.loginWithRedirect();
}
// recheck if the user was logged in successfully
// redirect to a public welcome page on failure
if (!auth || !auth.authenticated) {
console.log("failed to auth");
location.assign("https://stackmuncher.com");
}
// all navigation
return true;
});