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:

相关内容

热门资讯

通报透视"WePok... 通报透视"WePoker辅助挂教程"开挂(透视)辅助软件(一分钟了解切实教程)是一款可以让一直输的玩...
详细透视"wepok... 您好:wepoker德州一键透视购买的软件,软件加客服确实是有挂的,很多玩家在这款游戏中打牌都会发现...
实测透视"wepok... 您好:wepoker发牌规律这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用...
实测透视"wepok... >>您好:wepoker辅助挂有没有确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别好...
正品透视"Wepok... 您好:Wepoker最厉害三个组合的软件,软件加客服确实是有挂的,很多玩家在这款游戏中打牌都会发现很...
分析透视"wepok... 您好:wepoker开挂辅助方法这款游戏是可以开挂的,软件加【添加微信客服136704302】确实是...
实测透视"wepok... >>您好:wepoker发牌到底是不是随机软件加扣扣群确实是有挂的,很多玩家在这款游戏中打牌都会发现...
通报透视"wepok... 通报透视"wepoker辅助开挂方法"开挂(透视)辅助神器(重大通报揭秘教程)是一款可以让一直输的玩...
传授透视"WPK免费... >>>您好:,软件加微信【添加136704302】确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
教会透视"wepok... wepoker 发牌机制的原理是一款可以让一直输的玩家,快速成为一个“必胜”的ai辅助神器,有需要的...