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:

相关内容

热门资讯

黑科技辅助挂(Wepoke辅助... 黑科技辅助挂(Wepoke辅助器)外挂透视辅助助手(透视)确实真的是有挂(黑科技方法)1、Wepok...
黑科技能赢(德州之星辅助挂)外... 黑科技能赢(德州之星辅助挂)外挂黑科技辅助app(透视)真是存在有挂(黑科技细节)一、德州之星辅助挂...
黑科技规律(wepoke辅助器... 黑科技规律(wepoke辅助器真的有效果吗)外挂透明挂辅助下载(透视)都是是有挂(黑科技插件);1、...
黑科技好友房(微扑克有脚本吗)... 黑科技好友房(微扑克有脚本吗)外挂透视辅助教程(透视)果然是有挂(黑科技插件)1.微扑克有脚本吗 a...
黑科技插件(德扑ai工具)外挂... 黑科技插件(德扑ai工具)外挂透视辅助方法(透视)一贯是有挂(黑科技解说)1、游戏颠覆性的策略玩法,...
黑科技挂(德州之星有没有假)外... 黑科技挂(德州之星有没有假)外挂透明挂辅助插件(透视)总是是真的有挂(黑科技细节)1、德州之星有没有...
黑科技脚本(aa扑克外挂)外挂... 黑科技脚本(aa扑克外挂)外挂透视辅助教程(透视)切实真的是有挂(黑科技辅助)1)aa扑克外挂辅助挂...
黑科技软件(德扑之星辅助器购买... 黑科技软件(德扑之星辅助器购买)外挂透明挂辅助挂(透视)好像真的是有挂(黑科技插件)1、进入到德扑之...
黑科技好牌(wepoke插件)... 黑科技好牌(wepoke插件)外挂透明挂辅助挂(透视)真是是有挂(黑科技方法);1.wepoke插件...
黑科技脚本(wepoke辅助真... 黑科技脚本(wepoke辅助真的假的)外挂透明挂辅助安装(透视)都是是有挂(黑科技教程)一、wepo...