创建新用户而不重置当前用户会话 [英] Creating new users without resetting current user session

查看:95
本文介绍了创建新用户而不重置当前用户会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Parse Web应用程序中,我有一个用户管理页面,管理员可以访问该页面.该页面允许管理员创建新的用户帐户.

In my Parse web app, I have a user management page that is accessible to administrators. This page allows admins to create new user accounts.

要创建帐户,请使用Parse.User.signUp().

To create the accounts, I use Parse.User.signUp().

这很好用,但是它具有重置当前用户会话的讨厌的副作用,这会注销创建新用户帐户的管理员.

It works great, but it has the nasty side effect of resetting the current user session, which logs out the admin who created the new user account.

这实际上是已记录的行为, c1>:

This is actually the documented behaviour of User.signUp():

这将在服务器上创建一个新的Parse.User,并将会话保留在localStorage中,以便您可以使用#current访问该用户.

This will create a new Parse.User on the server, and also persist the session in localStorage so that you can access the user using #current.

但是我想创建新用户而不更改当前用户.我该怎么做?

But I want to create new users without changing the current user. How do I do this?

推荐答案

在使用User.signUp创建新用户帐户之前,请保存当前用户的sessionToken.然后,一旦创建了新用户,请使用User.become:

Before creating the new user account with User.signUp, save the current user's sessionToken. Then, once the new user has been created, restore the session with User.become:

var sessionToken = Parse.User.current().getSessionToken();

Parse.User.signUp(username, password).then(function(newUser) {
    Parse.User.become(sessionToken);
});

这篇关于创建新用户而不重置当前用户会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆