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.
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.
This is actually the documented behaviour of User.signUp()
:
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?
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);
});