Documentation Index
Fetch the complete documentation index at: https://mintlify.com/dreancaste/TriviaPP/llms.txt
Use this file to discover all available pages before exploring further.
AuthGuard is an Angular route guard that sits in front of every protected feature in TriviaPP. Before Angular renders a guarded page, the guard asynchronously checks whether the current device session contains a valid AWS Amplify authenticated user. If a session is found the navigation proceeds normally. If not, the guard cancels the navigation and redirects the player to /login. This prevents unauthenticated access to the trivia game, leaderboard, match history, and player profile without requiring any manual token inspection in individual components.
How It Works
AuthGuard implements Angular’s CanActivate interface and is provided in the root injector, making it available to any route in the application without additional module imports.
When Angular evaluates a route that declares canActivate: [AuthGuard], it calls canActivate() before resolving the component. The method delegates to AuthService.getCurrentUser(), which internally wraps Amplify’s getCurrentUser() function. If the call resolves with a user object the guard returns true and Angular proceeds with the navigation. If the call resolves with null — or throws because no active Cognito session exists — the guard calls this.router.navigate(['/login']) and returns false, aborting the intended navigation.
Protected Routes
The following routes declarecanActivate: [AuthGuard] in app-routing.module.ts and require an authenticated Amplify session to load:
| Path | Module |
|---|---|
home | HomePageModule |
profile | ProfilePageModule |
trivia | TriviaPageModule |
ranking | RankingPageModule |
history | HistoryPageModule |
Unprotected Routes
The following routes have nocanActivate guard and are accessible to any user regardless of authentication state:
| Path | Reason |
|---|---|
login | Sign-in entry point — must be reachable when logged out. |
register | New account creation — must be reachable before any session exists. |
wiki | Public Star Wars encyclopedia — intentionally open for unauthenticated browsing. |
wiki/characters | Wiki child route — inherits the public status of its parent. |
wiki/films | Wiki child route — inherits the public status of its parent. |
wiki/planets | Wiki child route — inherits the public status of its parent. |
wiki/detail/:type/:id | Wiki child route — inherits the public status of its parent. |
Session Persistence
AuthService.getCurrentUser() calls Amplify’s getCurrentUser() under the hood. Amplify manages the Cognito session tokens (access token, ID token, refresh token) automatically in device storage. When the app is reopened after a previous login, Amplify silently restores the session from storage and getCurrentUser() resolves with the existing user — so players are not prompted to log in again after closing and relaunching the app.
No manual JWT parsing, token storage, or expiry checking is required in application code. The guard trusts Amplify’s session resolution entirely.