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底牌透视脚本,wepoker透视破解版,安装教程(有挂教程)是一款可以让一直...
透视教程!hhpoker有辅助... 透视教程!hhpoker有辅助吗(透视)都是是真的有挂(详细辅助力荐教程);小薇(透视辅助)致您一封...
今日焦点!智星德州插件2024... 今日焦点!智星德州插件2024最新版,hhpoker作弊实战视频,2025新版技巧(有挂教程)是一款...
透视工具!hhpoker辅助挂... 透视工具!hhpoker辅助挂下载(透视)果然真的有挂(详细辅助切实教程)1、超多福利:超高返利,海...
总算了解!we poker插件... 总算了解!we poker插件,哈糖大菠萝万能挂,安装教程(有挂方法)准备好在哈糖大菠萝万能挂ia的...
透视私人局!佛手在线是不是有挂... 透视私人局!佛手在线是不是有挂(透视)总是真的是有挂(详细辅助AI教程)1、首先打开最新版本,在首页...
盘点几款!aapoker透视怎... 盘点几款!aapoker透视怎么用,约局吧能不能开挂,力荐教程(有挂透明);最新版2024是一款经典...
透视线上!wepoker私人局... 透视线上!wepoker私人局外卦(透视)竟然真的有挂(详细辅助解说技巧);1. ai辅助创建新账号...
实测必看!wepoker智能辅... 实测必看!wepoker智能辅助插件,wepoker轻量版透视系统,技巧教程(有挂透视)这是由厦门游...
透视游戏!wepoker作弊视... 透视游戏!wepoker作弊视频(透视)确实是有挂(详细辅助德州论坛)1、全新机制【软件透明挂】2、...