Skip to main content

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.

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.

What Amplify Provides

AuthService wraps the following Amplify Auth functions, all imported from aws-amplify/auth:
MethodAmplify functionDescription
register()signUpCreates a new Cognito user with email and password
confirmarRegistro()confirmSignUpVerifies the one-time code sent to the user’s email
login()signInAuthenticates the user and starts a session
logout()signOutSigns the user out and clears the local session
getCurrentUser()getCurrentUserReturns the currently authenticated user or null
obtenerTokenJWT()fetchAuthSessionReturns the Cognito ID token as a JWT string
The 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

1

Install the Amplify CLI

Install the Amplify CLI globally so it is available on your PATH:
npm install -g @aws-amplify/cli
2

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:
amplify configure
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.
3

Initialise Amplify in the TriviaPP project

From the root of the TriviaPP repository, run:
amplify init
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 appjavascript
  • Frameworkangular
  • Source directorysrc
  • Distribution directorywww/browser
  • Build commandnpm run build
  • Start commandnpm start
4

Add Authentication with Cognito

Add the Auth category to your Amplify backend:
amplify add auth
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.
5

Push the backend to AWS

Deploy the Cognito resources to your AWS account:
amplify push
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.
6

Configure Amplify in main.ts

TriviaPP configures Amplify programmatically in 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:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { Amplify } from 'aws-amplify';

Amplify.configure({
  Auth: {
    Cognito: {
      userPoolId: 'YOUR_USER_POOL_ID',
      userPoolClientId: 'YOUR_APP_CLIENT_ID',
    }
  }
});

platformBrowserDynamic()
  .bootstrapModule(AppModule)
  .catch((err) => console.error(err));
Replace 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 by src/app/services/auth.service.ts:
async register(email: string, password: string): Promise<SignUpOutput>

async confirmarRegistro(email: string, codigo: string): Promise<ConfirmSignUpOutput>

async login(email: string, password: string): Promise<SignInOutput>

async logout(): Promise<void>

async getCurrentUser(): Promise<any | null>

async obtenerTokenJWT(): Promise<string | null>

get userEmail(): string
All async methods delegate directly to the corresponding 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 calls register(), 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:
// 1. Register — triggers Cognito to send a code to the user's email
await authService.register('user@example.com', 'P@ssw0rd!');

// 2. Confirm — the user enters the code they received
await authService.confirmarRegistro('user@example.com', '123456');

// 3. Now the user can sign in
await authService.login('user@example.com', 'P@ssw0rd!');
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.

Build docs developers (and LLMs) love