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:

相关内容

热门资讯

wpk ai辅助!wepoke... 您好,wpk ai辅助这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在...
wepoke一定有挂!aapo... wepoke一定有挂!aapoker系统机制(透视)切实真的是有挂(详细辅助细节揭秘);无聊就玩这款...
微扑克ai辅助!fishpok... 微扑克ai辅助!fishpoker正规吗(透视)先前有挂(详细辅助扑克教程)1)微扑克ai辅助辅助挂...
aapoker辅助工具!wep... aapoker辅助工具!wepoke软件透明挂视频(透视)一贯真的有挂(详细辅助普及教程);小薇(透...
wpk提高胜率!哈糖大菠萝怎么... wpk提高胜率!哈糖大菠萝怎么弄的(透视)一直真的是有挂(详细辅助解密教程)(1)wpk提高胜率!哈...
wepoke辅助有挂!德州之星... wepoke辅助有挂!德州之星透牌器(透视)往昔真的是有挂(详细辅助软件教程)1、这是跨平台的wep...
德州AI智能辅助机器人!wpk... 德州AI智能辅助机器人!wpk微扑克有辅助(透视)确实有挂(详细辅助教你攻略)1、在德州AI智能辅助...
德扑ai助手!云扑克辅助(透视... 德扑ai助手!云扑克辅助(透视)本来有挂(详细辅助线上教程)1、构建自己的微扑克辅助插件;2、选择您...
智星德州菠萝偷偷看牌功能!we... 智星德州菠萝偷偷看牌功能!wepoke用模拟器(透视)往昔真的有挂(详细辅助软件教程);无聊就玩这款...
德州之星辅助!智星德州菠萝有挂... 德州之星辅助!智星德州菠萝有挂吗(透视)往昔真的有挂(详细辅助详细教程)1、构建自己的微扑克辅助插件...