ra-auth-cognito is an authentication provider designed specifically for React-Admin applications, integrating seamlessly with AWS Cognito user pools. The current stable version is 2.0.0, which introduced compatibility with React-Admin v5. The package typically releases new major versions aligned with React-Admin's major updates, alongside minor and patch releases for features and bug fixes. Key differentiators include robust support for username/password authentication, OAuth flows via AWS Hosted UI, and multi-factor authentication (MFA) including TOTP. It provides specialized components and hooks, such as `Login` and `useCognitoLogin`, to manage the initial login process for users with temporary passwords. This library simplifies common Cognito integration challenges within React-Admin, allowing developers to handle user identity, group-based permissions, and various authentication flows directly within their admin interfaces. Users must be pre-registered in Cognito with an email for the system to function correctly.
npm install ra-auth-cognitoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `ra-auth-cognito` with `react-admin` for username/password authentication. It configures the `CognitoAuthProvider` using a `CognitoUserPool` instance and sets the custom `Login` component to handle initial logins with temporary passwords, common in Cognito setups.
Upgrade `react-admin` to v5 or greater, or pin `ra-auth-cognito` to version 1.x if staying on an older `react-admin` version.
Ensure your `Admin` component's `loginPage` prop is set to the exported `Login` component, or implement a custom login page using the `useCognitoLogin` hook to handle the temporary password change flow.
Verify that users exist in your AWS Cognito User Pool and have a confirmed status with an email attribute.
Double-check your `CognitoAuthProvider` configuration parameters for `mode: 'oauth'` and ensure the `hostedUIUrl` and Cognito App Client redirect URLs match exactly.
Ensure your Cognito User Pool is configured with groups, and users are assigned to relevant groups to leverage `react-admin`'s permission-based access control.
Ensure the application handles temporary password changes on first login (using `<Login>` component). If not a first login, the user needs to re-authenticate. Check network requests for more specific Cognito error codes.
Verify that the `hostedUIUrl` in your `CognitoAuthProvider` configuration (if using OAuth) and the 'Callback URLs' list in your Cognito App Client settings in the AWS console are identical, including scheme (http/https), hostname, and path.
Either have the user complete the confirmation process (if email/SMS verification is enabled) or manually confirm the user in the AWS Cognito console.
Double-check that `UserPoolId` and `ClientId` environment variables or direct values are correctly set and passed to the `CognitoUserPool` constructor or `CognitoAuthProvider` options.