AWS Cognito User Pool Setup for SPA
Create User Pool
- Navigate to Amazon Cognito console.
- Click Create User Pool to start the setup process.
- Choose your Application Type and Sign-in Identifiers based on your application requirements.
- Select Required attributes such as email, given_name, family_name.

Configure the Sign-Up Experience
- Under Custom attributes, click Add custom attribute if you need additional user data.
- For example, add a username custom attribute:
- Attribute name: username
- Data type: String
- Set Mutable to allow users to update this attribute after account creation.
- Configure other custom attributes as needed for your business requirements.

Retrieve Configuration Values
- User Pool ID
- Found in the User Pool Overview page
- Format: ap-southeast-1_XXXXXXXXX
- App Client ID
- Found in Applications → App Clients section
- Format: xxxxxxxxxxxxxxxxxxxx
- Enable user registration and sign-in functionality
- Manage user attributes and profiles
- Handle email verification workflows
- Secure your SPA with JWT tokens
Frontend Integration with AWS Amplify
Installation
npm install aws-amplify
Configuration
lib / amplify-config.ts
import { Amplify } from 'aws-amplify';
const amplifyConfig = {
Auth: {
Cognito: {
userPoolId: 'ap-southeast-1_XXXXXXXXX', // Your User Pool ID
userPoolClientId: 'xxxxxxxxxxxxxxxxxxxx', // Your App Client ID
signUpVerificationMethod: 'code'
}
}
};
Amplify.configure(amplifyConfig);
Authentication Methods
Method | Sample Code |
---|---|
User Registration | import { signUp } from 'aws-amplify/auth';
await signUp({
username: email,
password: password,
options: {
userAttributes: {
email: email,
given_name: first_name,
family_name: last_name,
'custom:username': username
}
}
}); |
Email Verification | import { confirmSignUp } from 'aws-amplify/auth';
await confirmSignUp({
username: email,
confirmationCode: code
}); |
User Login | import { signIn } from 'aws-amplify/auth';
await signIn({
username: email,
password: password
}); |
Get Current User | import { getCurrentUser } from 'aws-amplify/auth';
const user = await getCurrentUser(); |
User Logout | import { signOut } from 'aws-amplify/auth';
await signOut(); |