{"library":"ra-auth-cognito","title":"ra-auth-cognito React-Admin Authentication Provider","description":"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.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install ra-auth-cognito"],"cli":null},"imports":["import { CognitoAuthProvider } from 'ra-auth-cognito';","import { Login } from 'ra-auth-cognito';","import { LoginForm } from 'ra-auth-cognito';","import { useCognitoLogin } from 'ra-auth-cognito';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import React from 'react';\nimport { Admin, Resource } from 'react-admin';\nimport { CognitoAuthProvider, Login } from 'ra-auth-cognito';\nimport { CognitoUserPool } from 'amazon-cognito-identity-js';\n\n// Mock data provider and resources for demonstration\nconst dataProvider = {\n    getList: () => Promise.resolve({ data: [{ id: 1, title: 'Post 1' }], total: 1 }),\n    getOne: () => Promise.resolve({ data: { id: 1, title: 'Post 1' } }),\n    getMany: () => Promise.resolve({ data: [{ id: 1, title: 'Post 1' }] }),\n    getManyReference: () => Promise.resolve({ data: [{ id: 1, title: 'Post 1' }], total: 1 }),\n    update: () => Promise.resolve({ data: { id: 1, title: 'Post 1' } }),\n    updateMany: () => Promise.resolve({ data: [{ id: 1, title: 'Post 1' }] }),\n    create: () => Promise.resolve({ data: { id: 1, title: 'New Post' } }),\n    delete: () => Promise.resolve({ data: { id: 1, title: 'Post 1' } }),\n    deleteMany: () => Promise.resolve({ data: [{ id: 1, title: 'Post 1' }] })\n};\nconst posts = { list: () => <div>Posts List</div>, edit: () => <div>Edit Post</div> };\n\n// Ensure these environment variables are set in your .env file or build process\nconst userPoolId = process.env.REACT_APP_COGNITO_USERPOOL_ID ?? 'us-east-1_XXXXX';\nconst clientId = process.env.REACT_APP_COGNITO_APP_CLIENT_ID ?? 'XXXXXXXXXXXX';\n\nconst userPool = new CognitoUserPool({\n    UserPoolId: userPoolId,\n    ClientId: clientId\n});\n\nconst authProvider = CognitoAuthProvider(userPool);\n\nconst App = () => {\n    if (!userPoolId || !clientId) {\n        console.error('Cognito UserPoolId or ClientId not set. Please check your environment variables.');\n        return <div>Configuration Error: Cognito details missing.</div>;\n    }\n    return (\n        <Admin\n            authProvider={authProvider}\n            dataProvider={dataProvider}\n            title=\"Example Admin\"\n            loginPage={Login} // Use the provided Login component for temporary password handling\n        >\n            <Resource name=\"posts\" {...posts} />\n        </Admin>\n    );\n};\n\nexport default App;\n","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}