How to use Amazon Cognito without Amplify
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Amplify is a convenient wrapper around Amazon Cognito, but it is not required. If you want tighter control over authentication flows, bundle size, or framework integration, you can talk to Cognito directly through the AWS SDK and standard HTTP APIs.
The Pieces You Actually Need
For most applications, Cognito usage without Amplify comes down to four parts:
- a User Pool for user accounts,
- an App Client for your application,
- optional Hosted UI settings if you want OAuth sign-in,
- direct SDK calls for sign-up, sign-in, token refresh, and password reset.
If you are building a browser or mobile app, do not create the app client with a secret unless you have a backend that can safely hold it. Public clients should avoid secrets because the client code is visible to users.
Direct Sign-In With the AWS SDK
A straightforward pattern is to use the Cognito Identity Provider API directly. The example below signs in a user with username and password using the JavaScript AWS SDK v3.
This returns the token set if the app client allows the chosen auth flow. In many cases, USER_PASSWORD_AUTH is the simplest way to start, especially for server-side code or controlled applications.
Sign-Up and Confirmation
User registration is also a direct API call. You create the user and then confirm the verification code sent by email or SMS.
This direct approach gives you full control over the UI and error handling instead of accepting Amplify's abstraction.
Working With Tokens
After sign-in, Cognito returns an ID token, access token, and usually a refresh token. The ID token describes the user. The access token is used for authorization against Cognito-aware APIs. The refresh token is used to get new short-lived tokens without asking the user to log in again.
In a web app, store tokens carefully. Prefer an HTTP-only cookie strategy if you have a backend. If the app is purely client-side, minimize exposure and be disciplined about expiry and logout handling.
For backend APIs, verify the JWT before trusting it. That step is independent of Amplify. The important rule is simple: Cognito issues the token, but your application is still responsible for validating it.
Hosted UI Without Amplify
If you want social login or OAuth redirect flows, you can still use Cognito's Hosted UI without Amplify. In that setup, Cognito handles the login screen and redirects back to your app with an authorization code or tokens, depending on the flow you configured.
That route is often simpler than building password screens yourself when you need:
- Google or Apple sign-in,
- enterprise identity federation,
- a standard OAuth redirect workflow,
- less custom password-handling code.
When Going Without Amplify Makes Sense
Direct Cognito integration is useful when:
- you already have an existing frontend architecture,
- you want smaller dependencies,
- you prefer explicit SDK calls,
- you need custom UI and error handling,
- you only use Cognito and do not want the rest of Amplify.
The tradeoff is that you must wire more pieces yourself, especially token storage, session refresh, and redirect handling.
Common Pitfalls
The most common problem is using an app client secret in a browser app. Secrets belong on the server, not in client-side JavaScript.
Another issue is enabling the wrong auth flows on the Cognito app client. If USER_PASSWORD_AUTH is not allowed, the sign-in request fails even though the code looks correct.
Teams also forget that Cognito authentication and JWT validation are separate concerns. Getting a token from Cognito is only half the job; your backend still needs to verify it before authorizing requests.
Summary
- Amplify is optional; Cognito can be used directly through the AWS SDK.
- The core pieces are a User Pool, an App Client, and the right auth flow settings.
- Use direct API calls for sign-up, confirmation, sign-in, and token refresh.
- Avoid app client secrets in public client applications.
- Validate Cognito-issued tokens in your backend instead of trusting them blindly.
Related reading
- How to use auto increment for primary key id in dynamodb
- How to use aws-cli with local dynamoDB ?
- How to use AWS account_id variable in Terraform
- How to use AWS IoT to send/receive messages to/from Web Browser
- How to use aws nlb with nginx ingress controller for ssl
- How to use DynamoDB fine grained access control with Cognito User Pools?
- How to use AWS S3 CLI to dump files to stdout in BASH?
- How to use AWS SDK C XRay in a AWS Lambda Layer implemented in C called by a Lambda function in Python?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.