简体   繁体   English

放大flutter认证

[英]Amplify flutter authentication

I am trying to implement Amplify in my flutter project.我正在尝试在我的 flutter 项目中实现 Amplify。 I wanna to get userSub just after signing up a new user without login and account verify.我想在没有登录和帐户验证的情况下注册新用户后获得 userSub。 I am using email as a username.我使用 email 作为用户名。 Some others suggested to use Amplify.Auth.fetchAuthSession() but I think I can't use this method without login.其他一些人建议使用Amplify.Auth.fetchAuthSession()但我想我不能在没有登录的情况下使用这种方法。 Any help?有什么帮助吗?

You have to implement authentication after you can get user data.您必须在获得用户数据后实施身份验证。 Check the Documentation from Amplify检查来自 Amplify 的文档

SignUp报名

try {
  Map<String, String> userAttributes = {
    'email': 'email@domain.com',
    'phone_number': '+15559101234',
    // additional attributes as needed
  };
  SignUpResult res = await Amplify.Auth.signUp(
    username: 'myusername',
    password: 'mysupersecurepassword',
    options: CognitoSignUpOptions(
      userAttributes: userAttributes
    )
  );
  setState(() {
    isSignUpComplete = res.isSignUpComplete;
  });
} on AuthException catch (e) {
  print(e.message);
}

ConfirmSignUP确认注册

try {
  SignUpResult res = await Amplify.Auth.confirmSignUp(
    username: 'myusername',
    confirmationCode: '123456'
  );
  setState(() {
    isSignUpComplete = res.isSignUpComplete;
  });
} on AuthException catch (e) {
  print(e.message);
}

SignIn登入

try {
  SignInResult res = await Amplify.Auth.signIn(
    username: usernameController.text.trim(),
    password: passwordController.text.trim(),
  );
  setState(() {
    isSignedIn = res.isSignedIn;
  });
} on AuthException catch (e) {
  print(e.message);
}

Follow this video tutoril you can implement Amplify Auth using BLOC architecture按照这个视频教程,您可以使用 BLOC 架构实现 Amplify Auth

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM