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辅助哪里买,微信小程序微乐房间怎么辅助,竟然是真的有辅助方法(哔哩哔哩)暗藏猫腻,小编详...
做出回应!wepoker可以开... 做出回应!wepoker可以开透视吗,陕西挖坑辅助,好像存在有辅助插件(哔哩哔哩)陕西挖坑辅助是不是...
现有说明如下!wpk插件,微信... 现有说明如下!wpk插件,微信欢乐卡五星辅助,竟然真的有辅助app(哔哩哔哩)1、游戏颠覆性的策略玩...
据通报!如何下载wepoker... 据通报!如何下载wepoker安装包,新西部辅助是什么意思,好像有辅助插件(哔哩哔哩)1、完成新西部...
目前!hhpoker有作必弊的... 目前!hhpoker有作必弊的吗,潮汕馆辅助,一直是有辅助工具(哔哩哔哩)1、下载好潮汕馆辅助脚本下...
截至目前!wepoker透视底... 截至目前!wepoker透视底牌脚本,凑一桌游戏免费辅助器,好像真的有辅助技巧(哔哩哔哩)凑一桌游戏...
日前!wepoker作必弊视频... 日前!wepoker作必弊视频,潮汕暗宝辅助器,切实是真的有辅助工具(哔哩哔哩)1.潮汕暗宝辅助器 ...
此事引发广泛关注!hhpoke... 此事引发广泛关注!hhpoker是内部控制吗,打哈儿麻将辅助下载,切实有辅助app(哔哩哔哩)1、每...
据权威媒体报道!hhpoker... 据权威媒体报道!hhpoker辅助挂下载,九游破解辅助插件,本来真的是有辅助工具(哔哩哔哩)1、每一...
网友热议!wepoker透视脚... 网友热议!wepoker透视脚本免费,约局吧辅助辅助外开挂,本来是真的有辅助方法(哔哩哔哩)1、约局...