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:

相关内容

热门资讯

透视普及"德扑圈透视... 透视普及"德扑圈透视挂"总是是有辅助插件(哔哩哔哩)该软件可以轻松地帮助玩家将德扑圈透视挂外卦神器提...
迎来新发展"wepo... 迎来新发展"wepoker辅助器是真的吗"哈糖大菠萝挂(其实是有辅助下载)-哔哩哔哩所有人都在同一条...
透视了解"哈糖大菠萝... 透视了解"哈糖大菠萝免费辅助器"都是是有辅助技巧(哔哩哔哩)该软件可以轻松地帮助玩家将哈糖大菠萝免费...
最新消息"wepok... 最新消息"wepoker有机器人吗"安装不了wepoker(一直存在有辅助下载)-哔哩哔哩1.wep...
最终"aapoker... 最终"aapoker辅助软件合法吗"uupoker透视(好像是有辅助下载)-哔哩哔哩1.aapoke...
透视科普"wepok... 透视科普"wepoker透视脚本免费使用视频"切实真的有辅助器(哔哩哔哩)1、完成wepoker透视...
透视解迷"wepok... 透视解迷"wepokerplus外开挂"真是真的有辅助技巧(哔哩哔哩)1、让任何用户在无需wepok...
透视规律"拱趴大菠萝... 透视规律"拱趴大菠萝万能挂"pokemmo手机辅助软件(切实真的有辅助安装)-哔哩哔哩1、超多福利:...
透视总结"德普软件&... 透视总结"德普软件"真是真的是有辅助教程(哔哩哔哩)1、德普软件公共底牌简单,德普软件透视插件操作,...
透视脚本"破解辅助插... 透视脚本"破解辅助插件wepoker"wepoker怎么开辅助(一直真的是有辅助神器)-哔哩哔哩1、...