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:

相关内容

热门资讯

透明辅助!川娱竞技有挂透视脚本... 【亲,川娱竞技有挂透视脚本 这款游戏可以开挂的,确实是有挂的,很多玩家在这款川娱竞技有挂透视脚本中打...
透视科技!雀友会辅助潮汕麻将脚... 您好:这款雀友会辅助潮汕麻将脚本游戏是可以开挂的,确实是有挂的,很多玩家在这款雀友会辅助潮汕麻将脚本...
透视好牌!小程序微乐辅助软件,... 大家好,今天小编来为大家解答小程序微乐辅助软件这个问题咨询软件客服可以免费测试直接加微信(13670...
透明总结!werplan脚本,... 您好:拱趴大菠萝万能辅助器这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户...
透视智能ai!黑侠破解约局吧,... 透视智能ai!黑侠破解约局吧,wepoker私人局怎么玩(辅助挂)详细开挂辅助挂;打开点击测试直接进...
透视系统!天天辅助器透视,aa... aapoker怎么设置提高好牌几率是一款专注玩家量身打造的游戏记牌类型软件,在aapoker怎么设置...
透视透明!越乡游义乌透视下载,... >>您好:越乡游义乌透视下载确实是有挂的,很多玩家在这款越乡游义乌透视下载游戏中打牌都会发现很多用户...
透视智能ai!手机挂机软件,c... 透视智能ai!手机挂机软件,cloudpoker作弊(辅助挂)详细开挂辅助挂;无需打开直接搜索加(薇...
透明工具!途游游戏辅助软件,w... 大家好,今天小编来为大家解答途游游戏辅助软件这个问题咨询软件客服可以免费测试直接加微信(136704...
透明透视!丽水都来大菠萝脚本辅... 透明透视!丽水都来大菠萝脚本辅助,来玩app破解版(辅助挂)详细开挂辅助工具;无需打开直接搜索薇:1...