@20i/cognito-react 中文文档教程
@20i/cognito-react
一个很好的 api,用于初始化 Cognito 并与之交互 反应。
Peer dependencies
"@aws-amplify/auth": "^4.0.3",
"react": "^17.0.2",
"react-query": "3.19.0",
"axios": "^0.21.1",
"react-dom": "^17.0.2"
Installation
npm login
npm i @20i/20i-cognito-react
Usage
import { Cognito } from "@20i/cognito-react"
import config from "./config"
const { cognito } = config
Cognito.configure(cognito)
const hooks = Cognito.Hooks((authUser: CognitoUser) => {
const user = getUser(authUser)
// Do stuff with the Cognito AuthUser to get the rest of the user data
// (Like retrieve it from the DB, etc)
return user
})
// The hooks returned from Cognito.Hooks will use the supplied lambda
// to retrieve the user in their respective logicks
export const useUser = hooks.useUser
export const useAuthUser = hooks.useAuthUser
@20i/cognito-react
A nice api to initialize and interact with Cognito from React.
Peer dependencies
"@aws-amplify/auth": "^4.0.3",
"react": "^17.0.2",
"react-query": "3.19.0",
"axios": "^0.21.1",
"react-dom": "^17.0.2"
Installation
npm login
npm i @20i/20i-cognito-react
Usage
import { Cognito } from "@20i/cognito-react"
import config from "./config"
const { cognito } = config
Cognito.configure(cognito)
const hooks = Cognito.Hooks((authUser: CognitoUser) => {
const user = getUser(authUser)
// Do stuff with the Cognito AuthUser to get the rest of the user data
// (Like retrieve it from the DB, etc)
return user
})
// The hooks returned from Cognito.Hooks will use the supplied lambda
// to retrieve the user in their respective logicks
export const useUser = hooks.useUser
export const useAuthUser = hooks.useAuthUser