前提:我是新手,所以我知道我的一些問題或問題對于更有經驗的人來說可能聽起來很明顯。
我的情況是:我有一個現有的 React 前端和 Node 后端。我需要向我的應用程式添加身份驗證,以便我可以為我的同事提供登錄(和將來的注冊)。我們使用 AWS 資源,并且 Cognito 中有一個現有的用戶池。
我該怎么做呢?
我進行了一些研究,一切都指向 AWS Amplify,但我發現現有資源非常混亂。Amplify 似乎在我運行時創建了一個新的、單獨的后端amplify init,但我需要堅持使用現有的后端。
基本上,我需要的只是身份驗證部分,我不想使用 Amplify 本身的任何其他內容。
如果我可能錯過了一些明顯的事情,請提前道歉。謝謝。
uj5u.com熱心網友回復:
我已經用Amplify庫解決了這個確切的情況。
您可以使用檔案所在的Authenticator組件here。@aws-amplify/ui-react
在最簡單的形式中,它看起來像這樣:
import { Authenticator } from "@aws-amplify/ui-react";
import Amplify from "aws-amplify";
Amplify.configure(awsExports);
const App = () => {
return (
<Authenticator>
{/* Pass app entry as children */}
{({ signOut, user }) => <Home signOut={signOut} user={user} />}
</Authenticator>
);
};
//Object holding AWS auth config
//This is a seperate file which is imported
export const awsExports = {
Auth: {
mandatorySignIn: true,
region: "YOUR REGION",
userPoolId: "COGNITO_POOL_ID",
userPoolWebClientId: "COGNITO_CLIENT_ID",
},
};
所以在我的應用程式中,我只使用這個 Authenticator 組件,它與 cognito 池進行所有互動,而 Amplify 沒有其他任何東西。您可以將許多不同的道具傳遞到 Authenticator 組件中,因此請務必查看檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/494909.html
