TriviaPP uses AWS Amplify as its authentication backend, backed by an Amazon Cognito User Pool. Amplify handles the full identity lifecycle — account creation, email-based verification, session management, and JWT token retrieval — while Firebase is used only for Firestore (the leaderboard) and plays no role in authentication.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.
What Amplify Provides
AuthService wraps the following Amplify Auth functions, all imported from aws-amplify/auth:
| Method | Amplify function | Description |
|---|---|---|
register() | signUp | Creates a new Cognito user with email and password |
confirmarRegistro() | confirmSignUp | Verifies the one-time code sent to the user’s email |
login() | signIn | Authenticates the user and starts a session |
logout() | signOut | Signs the user out and clears the local session |
getCurrentUser() | getCurrentUser | Returns the currently authenticated user or null |
obtenerTokenJWT() | fetchAuthSession | Returns the Cognito ID token as a JWT string |
userEmail getter exposes the signed-in user’s login ID in memory, populated on both login() and getCurrentUser() calls.
Prerequisites
- An AWS account with permissions to create Cognito User Pools and IAM users.
- Node.js and npm already available in your development environment.
The
aws-amplify package (v6+) is already listed as a dependency in package.json and will be installed when you run npm install. You do not need to install it separately.Setup
Configure the CLI with your AWS credentials
Run the interactive configuration wizard. It will open the AWS console to help you create a dedicated IAM user for Amplify, then ask you to paste the resulting access key and secret:Follow the prompts to select your AWS region, create an IAM user with
AdministratorAccess-Amplify permissions, and save the credentials to your local AWS profile.Initialise Amplify in the TriviaPP project
From the root of the TriviaPP repository, run:When prompted, choose the following:
- Enter a name for the environment — e.g.
dev - Choose your default editor — your preferred editor
- Choose the type of app —
javascript - Framework —
angular - Source directory —
src - Distribution directory —
www/browser - Build command —
npm run build - Start command —
npm start
Add Authentication with Cognito
Add the Auth category to your Amplify backend:Select Default configuration when asked how you want to configure the auth resource. This sets up a Cognito User Pool with email as the sign-in identifier, which matches what
AuthService passes to signUp and signIn as username.Push the backend to AWS
Deploy the Cognito resources to your AWS account:Confirm the proposed changes when prompted. Once the push completes, note the User Pool ID and App Client ID from the Amplify console output — you will need these in the next step.
Configure Amplify in main.ts
TriviaPP configures Amplify programmatically in Replace
src/main.ts using Amplify.configure() before the Angular application bootstraps. Open src/main.ts and update the Cognito identifiers with the values from your own User Pool:YOUR_USER_POOL_ID with your Cognito User Pool ID (e.g. us-east-2_XXXXXXXXX) and YOUR_APP_CLIENT_ID with the App Client ID created by amplify push.AuthService Method Signatures
The following public API is provided bysrc/app/services/auth.service.ts:
aws-amplify/auth function and propagate any errors thrown by Amplify (e.g. UserNotFoundException, NotAuthorizedException) without swallowing them, so the calling component is responsible for displaying appropriate error messages.
Email Confirmation Flow
After a user callsregister(), Cognito automatically sends a verification code to the provided email address. The user must enter this code in the app before they can sign in. The confirmation is performed by calling confirmarRegistro(email, codigo), which internally calls confirmSignUp:
If
Amplify.configure() in src/main.ts contains incorrect or missing Cognito identifiers, every call to AuthService will throw at runtime and users will be unable to register, log in, or access any route guarded by the authentication check. Always confirm the User Pool ID and App Client ID are correct before running or distributing the app.