作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 xcode 11.4,Swift 4 上。目标是:
UID
注册后,我会在
Firestore
中创建一个关联的用户记录。用这样的键
UID
.然后在用户登录/身份验证时,我可以得到这个
UID
从 firebase auth 并在 firestore 中找到相关记录。
schema.graphql
中创建了一个用户模型作为:
type User @model @auth(rules: [{ allow: owner, ownerField: "id", operations: [create, update, delete]}]){
id: ID!
firstName : String
lastName : String
handle : String
email : String!
}
SignUpController
的某个地方我创建一个新用户:
AWSMobileClient.default().signUp( username: email
, password: password
, userAttributes: ["email": email]) { (signUpResult, error) in
if let signUpResult = signUpResult {
switch(signUpResult.signUpConfirmationState) {
case .confirmed:
self.showAlert(msg: "You already have an account. Please go back and press log in")
case .unconfirmed:
break
case .unknown:
self.showAlert(msg: "Network error")
}
} else if let error = error { ... }
AWSMobileClient.default().confirmSignUp(username: email, confirmationCode: code) { (signUpResult, error) in
if let signUpResult = signUpResult {
switch(signUpResult.signUpConfirmationState) {
case .confirmed:
// This is where I need to create an associated user account
break
case .unconfirmed:
self.showAlert(title: "Error", msg: "User is not confirmed and needs verification via \(signUpResult.codeDeliveryDetails!.deliveryMedium) sent at \(signUpResult.codeDeliveryDetails!.destination!)")
case .unknown:
self.showAlert(title: "Error", msg: "Network error")
}
} else { //if let error = error {
self.showAlert(title: "Error", msg: "Network error")
}
case .confirmed
中的解决方案是立即登录,然后获取用户的
client token
通过:
class CognitoPoolProvider : AWSCognitoUserPoolsAuthProviderAsync {
/// this token may not be what you want ...
func getLatestAuthToken(_ callback: @escaping (String?, Error?) -> Void) {
AWSMobileClient.default().getTokens { (token, error) in
if let error = error {
callback(nil,error)
}
callback(token?.accessToken?.tokenString, error)
}
}
}
最佳答案
正确的方法是不要相信客户端从 Cognito 创建关联用户信息,您必须在服务器端进行。
您应该为 Cognito 创建一个新的 Lambda Post Confirmation Trigger 并对其进行编码以创建关联账户。您可以使用 event.userName
或创建自定义属性 uuid 类型喜欢 custom:id
链接您的关联帐户。
引用:https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-post-confirmation.html
关于swift - 将来自 Cognito 的用户信息与 AWS Amplify GraphQL 相关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61310638/
我是一名优秀的程序员,十分优秀!