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:

相关内容

热门资讯

透视有挂!约局吧开挂,情怀西游... 透视有挂!约局吧开挂,情怀西游辅助(原来是真的有挂);1、下载好情怀西游辅助辅助软件之后点击打开,先...
透视工具!线上德州的辅助器是什... 透视工具!线上德州的辅助器是什么,荆州圣盛游戏辅助(都是存在有挂);1、金币登录送、破产送、升级送、...
透视游戏!德普之星透视辅助软件... 透视游戏!德普之星透视辅助软件是真的吗,贵州闲来辅助工具(总是存在有挂);小薇(透视辅助)致您一封信...
透视工具!wepokerplu... 透视工具!wepokerplus透视脚本免费,边锋干橙眼辅助器的主要功能是什么(确实存在有挂);1、...
透视辅助!hhpoker作弊码... 透视辅助!hhpoker作弊码怎么用,微新欢乐卡五星辅助(原来存在有挂)1、构建自己的微新欢乐卡五星...
透视模拟器!hhpoker智能... 透视模拟器!hhpoker智能辅助插件,新众亿免费辅助(切实是真的有挂);新众亿免费辅助是一种具有地...
透视插件!wepoker透视脚... 透视插件!wepoker透视脚本视频,闲逸有没有辅助软件功能(原来真的是有挂)1、许多玩家不知道闲逸...
透视线上!pokemomo辅助... 透视线上!pokemomo辅助软件,老友广东辅助工具(其实真的是有挂)亲,关键说明,老友广东辅助工具...
透视苹果版!we-poker辅... 透视苹果版!we-poker辅助,星悦游戏填坑辅助器(本来真的是有挂)星悦游戏填坑辅助器是一种具有地...
透视脚本!wepoker可以免... 透视脚本!wepoker可以免费玩吗,广东插件智能插件安装包免费(总是是有挂)1、让任何用户在无需广...