AutoSigninafterSigningupusinginvitationsignuppolicy(在邀请注册策略后注册后自动登录)
创始人
2024-11-12 15:00:50
0

使用AWS Cognito的API进行登录,即在注册后直接调用API进行登录。

示例代码:

import AWS from 'aws-sdk';
import { CognitoUserPool, CognitoUserAttribute, CognitoUser } from 'amazon-cognito-identity-js';
const region = 'us-east-1';
const identityPoolId = 'YOUR_IDENTITY_POOL_ID';

// 在邀请注册策略下注册并直接登录
const signUpAndLogin = async (name, email, password, invite) => {
  // create callback promise
  const callbackPromise = () => {
    return new Promise((resolve, reject) => {
      const cognitoUserPool = new CognitoUserPool({
        UserPoolId: 'YOUR_USER_POOL_ID',
        ClientId: 'YOUR_APP_CLIENT_ID',
        region: region,
      });
      const attributeList = [
        new CognitoUserAttribute({
          Name: 'custom:invite',
          Value: invite,
        }),
        new CognitoUserAttribute({
          Name: 'email',
          Value: email,
        }),
        new CognitoUserAttribute({
          Name: 'name',
          Value: name,
        }),
      ];

      cognitoUserPool.signUp(email, password, attributeList, null, (err) => {
        if (err) {
          reject(err);
        }
        resolve();
      });
    });
  };

  await callbackPromise();

  // login after sign up
  const getIdToken = () => {
    return new Promise((resolve, reject) => {
      AWS.config.region = region;
      AWS.config.credentials = new AWS.CognitoIdentityCredentials({
        IdentityPoolId: identityPoolId,
      });
      const cognitoUser = new CognitoUser({
        Username: email,
        Pool: new CognitoUserPool({
          UserPoolId: 'YOUR_USER_POOL_ID',
          ClientId: 'YOUR_APP_CLIENT_ID',
          region: region,
        }),
      });
      const authenticationDetails = new AuthenticationDetails({
        Username: email,
        Password: password,
      });
      cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function (result) {
          resolve(result.getIdToken().getJwtToken());
        },
        onFailure:

相关内容

热门资讯

黑科技辅助!wpk,(WPK线... 黑科技辅助!wpk,(WPK线上德州)原来真的有挂,详细教程(猫腻)-哔哩哔哩;WPK线上德州最新版...
黑科技辅助!Wepoke透明挂... 黑科技辅助!Wepoke透明挂,(WePoKe设备)原来真的有挂,教你教程(有挂实锤)-哔哩哔哩是一...
黑科技辅助!aapoker有外... 黑科技辅助!aapoker有外挂,(AAPoKer德州局)原来真的有挂,科技教程(真的)-哔哩哔哩;...
黑科技辅助!wepoke插件,... 黑科技辅助!wepoke插件,(Wepoke网页版)原来真的有挂,必赢方法(有挂攻略)-哔哩哔哩;1...
黑科技辅助!wepoke可以看... 您好,Wepoke总结这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在...
黑科技辅助!德扑之星辅牌软件,... 黑科技辅助!德扑之星辅牌软件,(德扑手牌)原来真的有挂,规律教程(确实)-哔哩哔哩是一款可以让一直输...
黑科技辅助!微扑克ai辅助神器... 黑科技辅助!微扑克ai辅助神器,(微扑克ai智能)原来真的有挂,攻略教程(方式)-哔哩哔哩是一款可以...
黑科技辅助!aapoker透明... 黑科技辅助!aapoker透明,(AAPoKer线上德州)原来真的有挂,规律教程(方式)-哔哩哔哩;...
黑科技辅助!we-poker有... 黑科技辅助!we-poker有挂,(WePoKe ai)原来真的有挂,安装教程(有挂工具)-哔哩哔哩...
黑科技辅助!Wepoke辅助器... 黑科技辅助!Wepoke辅助器,(WePoKe链接)原来真的有挂,详细教程(有挂辅助)-哔哩哔哩;W...