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:

相关内容

热门资讯

透视系统"poker... 透视系统"poker红龙辅助"详细辅助必赢方法(最初有挂);建议优先通过poker红龙辅助透明挂内置...
今日科普!wepoker亲友圈... 今日科普!wepoker亲友圈有用吗,pokerworld破解版下载,技巧教程(有挂软件);科技安装...
透视脚本"大菠萝78... 透视脚本"大菠萝789辅助器下载"详细辅助AA德州教程(原生是有挂)是一款可以让一直输的玩家,快速成...
推荐十款!德扑之心免费透视,a... 推荐十款!德扑之心免费透视,aapoker安装包怎么使用,解说技巧(有挂技巧);大神普及一款德州ai...
透视黑科技"wepo... 透视黑科技"wepoker买脚本靠谱吗"详细辅助教你攻略(总是是真的有挂);小薇(透视辅助)致您一封...
揭秘一下!aapoker破解侠... 揭秘一下!aapoker破解侠是真的吗,wepokerplus到底是挂了吗,新2025教程(有挂技巧...
透视插件"菠萝辅助器... 这是一款非常优秀的菠萝辅助器免费版的特点 ia辅助检测软件,能够让你了解到菠萝辅助器免费版的特点中牌...
安装程序教程!佛手在线大菠萝智... 安装程序教程!佛手在线大菠萝智能辅助器,佛手在线大菠萝技巧,介绍教程(有挂神器)关于佛手在线大菠萝智...
透视计算"wejok... 透视计算"wejoker黑侠辅助器"详细辅助透明挂教程(真是有挂);《WPK辅助透视》‌:支持手机实...
一分钟揭秘!wejoker辅助... 自定义uupoker有透视吗系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器...