Resolves Issue #121 (Add AuthGuard to redirect non-logged in uses who attempt to access /home or /event to the /intro page).
As an admin, I only want logged in users to have access to the Home and Event pages, and to have non-logged in users redirected to the Intro page. If a user attempts to access the Home or Event page directly, I want to ensure they are logged in before accessing user-specific pages.
This feature is addressed by introducing an auth.guard.ts and an auth.service.ts. Auth guard verifies if the page can be activated by checking that the user is logged in before displaying the page details. It makes use of the Auth Service which sets up determining if the user is logged in.
Previously, the home page had code that would parse the returned query string from the Cognito Hosted UI for the id_token, decode it and derive the "HostID" name, then save that information to sessionStorage to be used for determining what should be displayed on the Home Page. That code has been moved into the AuthService's login function (since the home page cannot be accessed at all until that info is saved).
[x] You should be rerouted to the /intro page. Console logs will indicate AuthGaurd was called and isLoggedIn is false.
[ ] from the intro page, select login/signup button.
[ ] Log in with established test user account.
[x] You should arrive at the home page, showing events for the logged in user. Console logs will indicate AuthGuard CanActivate was called, and will show AuthService's isLoggedIn variable set to true.
[ ] Select the "build an event" button
[x] You should arrive on the event page, showing the hostID as the logged in user. Console logs will indicate AuthGuard CanActivate was called, and will show AuthService's isLoggedIn variable set to true.
[ ] Select the topnav button to return to the Home page.
[x] You should return the Home Page as expected. Console logs should be the same as indicated above.
[ ] Hit the refresh button on your browser window
[x] Page should reload the Home Page as expected, and not reroute to the intro page. Console logs should indicate AuthService's isLoggedIn variable set to true.
[ ] Navigate directly to both the /home and /event pages as in Steps 2 and 3.
[ ] These should navigate to the desired pages without issue.
Resolves Issue #121 (Add AuthGuard to redirect non-logged in uses who attempt to access /home or /event to the /intro page).
As an admin, I only want logged in users to have access to the Home and Event pages, and to have non-logged in users redirected to the Intro page. If a user attempts to access the Home or Event page directly, I want to ensure they are logged in before accessing user-specific pages. This feature is addressed by introducing an auth.guard.ts and an auth.service.ts. Auth guard verifies if the page can be activated by checking that the user is logged in before displaying the page details. It makes use of the Auth Service which sets up determining if the user is logged in. Previously, the home page had code that would parse the returned query string from the Cognito Hosted UI for the id_token, decode it and derive the "HostID" name, then save that information to sessionStorage to be used for determining what should be displayed on the Home Page. That code has been moved into the AuthService's login function (since the home page cannot be accessed at all until that info is saved).
Tested on Win10 laptop, Chrome v92.
To Verify:
[ ] start fresh localhost instance of the app.
[ ] before logging in as a test user, attempt to go to "http://localhost:4200/home".
[ ] attempt to go to http://localhost:4200/event".
[ ] from the intro page, select login/signup button.
[ ] Log in with established test user account.
[ ] Select the "build an event" button
[ ] Select the topnav button to return to the Home page.
[ ] Hit the refresh button on your browser window
[ ] Navigate directly to both the /home and /event pages as in Steps 2 and 3.