Functions
generateUserAccessToken()
generateUserAccessToken(
params):Promise<string>
Defined in: cognito/generate-user-access-token.ts:37
Generates an access token using Cognito's InitiateAuth API with the USER_PASSWORD_AUTH flow.
Useful in E2E and integration tests when you need to authenticate as a specific user against protected APIs.
Parameters
params
UserAccessTokenParams
The authentication parameters
Returns
Promise<string>
The access token string
Throws
Error if the authentication request fails or required environment variables are missing
Example
// Minimal — uses USER_POOL_CLIENT_ID and AWS_REGION environment variables
const token = await generateUserAccessToken({
email: process.env.TEST_EMAIL,
password: process.env.TEST_PASSWORD,
});
// Explicit overrides
const token = await generateUserAccessToken({
region: 'us-east-1',
clientId: 'my-client-id',
email: process.env.TEST_EMAIL,
password: process.env.TEST_PASSWORD,
});