Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return this._authService.user.pipe(
- take(1),
- map(user => {
- console.log(user);
- return !!user;
- }),
- map(authenticated => {
- console.log(`Authenticated: ${authenticated}`);
- // not authenticated
- if (!authenticated) {
- // accessing sign in or sign up pages
- if (['/login', '/register'].includes(url)) {
- console.log('Allow through');
- return true;
- }
- // accessing application
- else {
- console.log('Should bounce to login');
- this._router.createUrlTree(['/login']);
- return false;
- }
- }
- // authenticated
- else {
- // accessing sign in or sign up pages
- if (['/login', '/register'].includes(url)) {
- console.log('Should bounce to dashboard');
- this._router.createUrlTree(['/dashboard']);
- return false;
- }
- // accessing application
- else {
- console.log('Allow through');
- return true;
- }
- }
- })
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement