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:

相关内容

热门资讯

透视玄学!aapoker辅助工... 《aapoker辅助工具免费下载软件透明挂》是一款多人竞技的aapoker辅助工具免费下载辅助透视游...
透视能赢!aapoker有脚本... 一、aapoker有脚本吗简介了解软件请加微:136704302aapoker有脚本吗是一款在线扑克...
透视科技!wepoker辅助透... 透视科技!wepoker辅助透视软件,wepoker私人局辅助挂,必备教程(最初真的有挂),亲,有的...
透视安卓版!wpk透视辅助,w... 您好,wpk透视辅助这款游戏可以开挂的,确实是有挂的,需要了解加Q群【1067239143】很多玩家...
透视数据!wepoker透视脚... 透视数据!wepoker透视脚本安卓,wepoker私人局外卦,wepoke教程(先前真的有挂);w...
透视智能ai!红龙poker透... 您好,aapoker辅助是真的吗这款游戏可以开挂的,确实是有挂的,需要了解加Q群【106723914...
透视app!德普之星辅助功能如... 这是一款非常优秀的德普之星辅助功能如何设置 ia辅助检测软件,能够让你了解到德普之星辅助功能如何设置...
透视了解!hhpoker免费透... 透视了解!hhpoker免费透视脚本,hhpoker开辅助软件,玩家必看科普(有挂详情)1、超多福利...
透视安装!智星德州菠萝透视插件... 透视安装!智星德州菠萝透视插件工具,wepoker有透视吗,透明挂教程(都是真的是有挂)智星德州菠萝...
辅助透视!德普之星透视辅助软件... 1、辅助透视!德普之星透视辅助软件是真的吗,wepoker作弊辅助,记者发布(有挂总结);详细教程。...