Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. return this._authService.user.pipe(
  2. take(1),
  3. map(user => {
  4. console.log(user);
  5. return !!user;
  6. }),
  7. map(authenticated => {
  8. console.log(`Authenticated: ${authenticated}`);
  9. // not authenticated
  10. if (!authenticated) {
  11. // accessing sign in or sign up pages
  12. if (['/login', '/register'].includes(url)) {
  13. console.log('Allow through');
  14. return true;
  15. }
  16. // accessing application
  17. else {
  18. console.log('Should bounce to login');
  19. this._router.createUrlTree(['/login']);
  20. return false;
  21. }
  22. }
  23. // authenticated
  24. else {
  25. // accessing sign in or sign up pages
  26. if (['/login', '/register'].includes(url)) {
  27. console.log('Should bounce to dashboard');
  28. this._router.createUrlTree(['/dashboard']);
  29. return false;
  30. }
  31. // accessing application
  32. else {
  33. console.log('Allow through');
  34. return true;
  35. }
  36. }
  37. })
  38. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement