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:

相关内容

热门资讯

据悉!wepoker破解器有用... 据悉!wepoker破解器有用吗(透视)来物局怎么开挂(竟然有辅助辅助器)-哔哩哔哩1、游戏颠覆性的...
辅助透视!wepoker辅助软... 辅助透视!wepoker辅助软件价格(透视)爱来大菠萝有挂吗(总是是有辅助插件)-哔哩哔哩1、首先打...
透视好牌!wepoker底牌透... 透视好牌!wepoker底牌透视(透视)h5游戏辅助修改器(真是真的有辅助插件)-哔哩哔哩1、每一步...
透视肯定!wpk辅助软件(透视... 透视肯定!wpk辅助软件(透视)微信新九游辅助(真是真的有辅助安装)-哔哩哔哩1)微信新九游辅助有没...
出现新变化!xpoker透视辅... 出现新变化!xpoker透视辅助(透视)赣南辅助是真的吗(都是是真的辅助平台)-哔哩哔哩1、赣南辅助...
透视计算!sohoo poke... 透视计算!sohoo poker辅助(透视)微信小程序决胜游戏辅助(切实有辅助下载)-哔哩哔哩1、实...
透视脚本!wpk是真的还是假的... 透视脚本!wpk是真的还是假的(透视)杭州都莱可以装挂吗(切实存在有辅助工具)-哔哩哔哩1、该软件可...
透视美元局!steampoke... 透视美元局!steampokermaster辅助(透视)一起宁德钓蟹技巧(本来有辅助平台)-哔哩哔哩...
出现新变化!wpk俱乐部有没有... 出现新变化!wpk俱乐部有没有辅助(透视)荔枝竞技辅助(其实是有辅助辅助器)-哔哩哔哩1、不需要AI...
长期以来!wepoker有没有... 长期以来!wepoker有没有插件(透视)邳州友友辅助app官网(切实是真的辅助app)-哔哩哔哩1...