簡體   English   中英

AWS Cognito 注冊和登錄 - 如何存儲池和應用程序 ID

[英]AWS cognito registration and login - how to store pool and app id

我使用這個例子來設置一個帶有AWS Cognito用戶池的注冊/登錄 UI: https : //medium.com/@gmonne/custom-authentication-using-aws-cognito-e0b489badc3f

作者建議通過創建一個將這些信息保存在兩個全局變量中的 config.js 文件來保持用戶池和應用程序 ID 的私密性。 readme.md

在運行此代碼之前,您應該在名為config.jsjavascript文件夾中創建一個 JavaScript 文件。 在這里,您應該使用名稱在窗口對象上設置您的“用戶池”ID 和應用程序客戶端 ID: USER_POOL_IDCLIENT_ID

我在 config.js 中設置變量如下,但得到一個USER_POOL_ID is not defined錯誤。

var USER_POOL_ID: "us-east-1_#######";
var APP_CLIENT_ID: "7pcmh9gre807########";

來自示例中的 cognito.js 文件:

(function(win, CognitoUserPool) {

var CognitoUserPool = window.AmazonCognitoIdentity.CognitoUserPool,
AWSCognito = window.AWSCognito,
CognitoIdentityServiceProvider = AWSCognito.CognitoIdentityServiceProvider,CognitoUserAttribute = CognitoIdentityServiceProvider.CognitoUserAttribute,
CognitoUser = CognitoIdentityServiceProvider.CognitoUser,
AuthenticationDetails = CognitoIdentityServiceProvider.AuthenticationDetails,
UserPool = new CognitoUserPool({
UserPoolId : window.USER_POOL_ID, // Your user pool id here
ClientId : window.CLIENT_ID, // Your client id here

如自述文件中所述,在窗口對象上設置 ID 的語法是什么?

使用= not :設置變量,因此更改config.js

var USER_POOL_ID = "us-east-1_#######";
var APP_CLIENT_ID = "7pcmh9gre807########";

不清楚這個文件是如何使用的,但如果你想直接設置窗口對象,你會這樣做

window.USER_POOL_ID = "us-east-1_#######";
window.APP_CLIENT_ID = "7pcmh9gre807########";

並且 cognito.js 代碼沒有使用正確的變量名,它沒有APP_前綴,因此將最后一行更改為:

ClientId : window.APP_CLIENT_ID, // Your client id here

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM