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:

相关内容

热门资讯

3分钟了解!jj斗地主麻将外g... 3分钟了解!jj斗地主麻将外g挂!真是一直都是有辅助神器(果真有挂)-哔哩哔哩1、jj斗地主麻将外g...
第三分钟了解!小闲川南手游辅助... 第三分钟了解!小闲川南手游辅助器!原来真的是有辅助脚本(揭秘有挂)-哔哩哔哩1、玩家可以在小闲川南手...
第6分钟了解!波特互娱辅助!其... 第6分钟了解!波特互娱辅助!其实一直总是有辅助方法(新版有挂)-哔哩哔哩;第6分钟了解!波特互娱辅助...
第三分钟了解!微乐小程序辅助教... 第三分钟了解!微乐小程序辅助教程!其实有辅助攻略(有挂总结)-哔哩哔哩1、这是跨平台的微乐小程序辅助...
一分钟了解!789大菠萝攻略!... 一分钟了解!789大菠萝攻略!确实是有辅助脚本(真的有挂)-哔哩哔哩789大菠萝攻略破解侠是真的助透...
第5分钟了解!微信十三张脚本!... 第5分钟了解!微信十三张脚本!切实一直总是有辅助方法(确实有挂)-哔哩哔哩一、微信十三张脚本可以开透...
八分钟了解!心悦填大坑技巧分析... 八分钟了解!心悦填大坑技巧分析器!其实真的有辅助插件(有挂方式)-哔哩哔哩1、实时心悦填大坑技巧分析...
第一分钟了解!中至上饶麻将有挂... 第一分钟了解!中至上饶麻将有挂开挂!其实有辅助插件(真的有挂)-哔哩哔哩运中至上饶麻将有挂开挂辅助工...
第二分钟了解!微信神兽大厅源代... 第二分钟了解!微信神兽大厅源代码!总是一直都是有辅助脚本(有挂头条)-哔哩哔哩1、不需要AI权限,帮...
八分钟了解!wepkerplu... 八分钟了解!wepkerplus辅助作弊!确实存在有辅助app(有挂规律)-哔哩哔哩该软件可以轻松地...