This repository was archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(authenticateStep): use authService.authenticate
- Loading branch information
1 parent
7e64bbf
commit 5b9306f
Showing
2 changed files
with
23 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
import {inject} from 'aurelia-dependency-injection'; | ||
import {Authentication} from './authentication'; | ||
import {Redirect} from 'aurelia-router'; | ||
|
||
@inject(Authentication) | ||
import {AuthService} from './authService'; | ||
|
||
@inject(AuthService) | ||
export class AuthenticateStep { | ||
constructor(authentication) { | ||
this.authentication = authentication; | ||
constructor(authService) { | ||
this.authService = authService; | ||
} | ||
|
||
run(routingContext, next) { | ||
const isLoggedIn = this.authentication.isAuthenticated(); | ||
const loginRoute = this.authentication.config.loginRoute; | ||
const isLoggedIn = this.authService.authenticated; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
RWOverdijk
Member
|
||
const loginRoute = this.authService.config.loginRoute; | ||
|
||
if (routingContext.getAllInstructions().some(i => i.config.settings.authenticate === true)) { | ||
if (routingContext.getAllInstructions().some(route => route.config.settings.authenticate === true)) { | ||
if (!isLoggedIn) { | ||
return next.cancel(new Redirect(loginRoute)); | ||
} | ||
} else if (isLoggedIn && routingContext.getAllInstructions().some(i => i.fragment === loginRoute)) { | ||
return next.cancel(new Redirect( this.authentication.config.loginRedirect )); | ||
} else if (isLoggedIn && routingContext.getAllInstructions().some(route => route.fragment === loginRoute)) { | ||
return next.cancel(new Redirect( this.authService.config.loginRedirect )); | ||
} | ||
|
||
return next(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I wonder why this change? I believe it causes a bug when using sessionStorage.
When I am using sessionStorage (and auth token is in the store) and I refresh the page, then this.authService.authenticated is false but this.authService.isAuthenticated() is true.