@20i/cognito-react 中文文档教程

发布于 3年前 浏览 31 项目主页 更新于 3年前

@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
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文