Constructor
new ParseUser(attributes)
Parameters:
Name | Type | Description |
---|---|---|
attributes |
object
|
The initial set of data to store in the user. |
Extends
Members
createdAt
The first time this object was saved on the server.
Properties:
Name | Type | Description |
---|---|---|
createdAt |
Date
|
- Overrides:
updatedAt
The last time this object was updated on the server.
Properties:
Name | Type | Description |
---|---|---|
updatedAt |
Date
|
- Overrides:
Methods
(static) _logInWith(provider, options, saveOpts) → {Promise}
- Deprecated:
- since 2.9.0 see logInWith
Parameters:
Name | Type | Description |
---|---|---|
provider |
||
options |
||
saveOpts |
Returns:
- Type:
-
Promise
(static) _registerAuthenticationProvider(provider)
When registering users with linkWith a basic auth provider is automatically created for you.
For advanced authentication, you can register an Auth provider to implement custom authentication, deauthentication.
Parameters:
Name | Type | Description |
---|---|---|
provider |
(static) allowCustomUserClass(isAllowed)
Allow someone to define a custom User class without className being rewritten to _User. The default behavior is to rewrite User to _User for legacy reasons. This allows developers to override that behavior.
Parameters:
Name | Type | Description |
---|---|---|
isAllowed |
boolean
|
Whether or not to allow custom User class |
(static) become(sessionToken, options) → {Promise}
Logs in a user with a session token. On success, this saves the session
to disk, so you can retrieve the currently logged in user using
current
.
Parameters:
Name | Type | Description |
---|---|---|
sessionToken |
string
|
The sessionToken to log in with. |
options |
object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled with the user when the login completes.
(static) current() → {Parse.Object}
Retrieves the currently logged in ParseUser with a valid session, either from memory or localStorage, if necessary.
(static) currentAsync() → {Promise}
Retrieves the currently logged in ParseUser from asynchronous Storage.
Returns:
- Type:
-
Promise
A Promise that is resolved with the currently logged in Parse User
(static) disableUnsafeCurrentUser()
Disables the use of become or the current user in any environment. These features are disabled on servers by default, since they depend on global objects that are not memory-safe for most servers.
(static) enableRevocableSession(options) → {Promise}
Allows a legacy application to start using revocable sessions. If the current session token is not revocable, a request will be made for a new, revocable session. It is not necessary to call this method from cloud code unless you are handling user signup or login from the server side. In a cloud code call, this function will not attempt to upgrade the current token.
Parameters:
Name | Type | Description |
---|---|---|
options |
object
|
Returns:
- Type:
-
Promise
A promise that is resolved when the process has completed. If a replacement session token is requested, the promise will be resolved after a new token has been fetched.
(static) enableUnsafeCurrentUser()
Enables the use of become or the current user in a server environment. These features are disabled by default, since they depend on global objects that are not memory-safe for most servers.
(static) extend(protoProps, classProps) → {Parse.User}
Adds functionality to the existing Parse.User class.
Parameters:
Name | Type | Description |
---|---|---|
protoProps |
object
|
A set of properties to add to the prototype |
classProps |
object
|
A set of static properties to add to the class |
(static) hydrate(userJSON) → {Promise}
Logs in a user with a session token. On success, this saves the session
to disk, so you can retrieve the currently logged in user using
current
. If there is no session token the user will not logged in.
Parameters:
Name | Type | Description |
---|---|---|
userJSON |
object
|
The JSON map of the User's data |
Returns:
- Type:
-
Promise
A promise that is fulfilled with the user when the login completes.
(static) logIn(username, password, options) → {Promise}
Logs in a user with a username (or email) and password. On success, this
saves the session to disk, so you can retrieve the currently logged in
user using current
.
Parameters:
Name | Type | Description |
---|---|---|
username |
string
|
The username (or email) to log in with. |
password |
string
|
The password to log in with. |
options |
object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled with the user when the login completes.
(static) logInWith(provider, options, saveOpts) → {Promise}
Static version of linkWith
Parameters:
Name | Type | Description |
---|---|---|
provider |
||
options |
||
saveOpts |
Returns:
- Type:
-
Promise
(static) logOut(options) → {Promise}
Logs out the currently logged in user session. This will remove the
session from disk, log out of linked services, and future calls to
current
will return null
.
Parameters:
Name | Type | Description |
---|---|---|
options |
object
|
Returns:
- Type:
-
Promise
A promise that is resolved when the session is destroyed on the server.
(static) me(sessionToken, options) → {Promise}
Retrieves a user with a session token.
Parameters:
Name | Type | Description |
---|---|---|
sessionToken |
string
|
The sessionToken to get user with. |
options |
object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled with the user is fetched.
(static) requestEmailVerification(email, options) → {Promise}
Request an email verification.
Parameters:
Name | Type | Description |
---|---|---|
email |
string
|
The email address associated with the user that forgot their password. |
options |
object
|
Returns:
- Type:
-
Promise
(static) requestPasswordReset(email, options) → {Promise}
Requests a password reset email to be sent to the specified email address associated with the user account. This email allows the user to securely reset their password on the Parse site.
Parameters:
Name | Type | Description |
---|---|---|
email |
string
|
The email address associated with the user that forgot their password. |
options |
object
|
Returns:
- Type:
-
Promise
(static) signUp(username, password, attrs, options) → {Promise}
Signs up a new user with a username (or email) and password. 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.
Parameters:
Name | Type | Description |
---|---|---|
username |
string
|
The username (or email) to sign up with. |
password |
string
|
The password to sign up with. |
attrs |
object
|
Extra fields to set on the new user. |
options |
object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled with the user when the signup completes.
(static) verifyPassword(username, password, options) → {Promise}
Verify whether a given password is the password of the current user.
Parameters:
Name | Type | Description |
---|---|---|
username |
string
|
A username to be used for identificaiton |
password |
string
|
A password to be verified |
options |
object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled with a user when the password is correct.
_cleanupAuthData()
Removes null values from authData (which exist temporarily for unlinking)
_clearPendingOps(keysToClearopt)
- Overrides:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
keysToClear |
Array.<string>
|
<optional> |
if specified, only ops matching these fields will be cleared |
_getId() → {string}
Returns a local or server Id used uniquely identify this object
- Overrides:
Returns:
- Type:
-
string
_getStateIdentifier() → {Parse.Object|object}
Returns a unique identifier used to pull data from the State Controller.
- Overrides:
Returns:
- Type:
-
Parse.Object
|object
_isLinked(provider) → {boolean}
Checks whether a user is linked to a service.
Parameters:
Name | Type | Description |
---|---|---|
provider |
object
|
service to link to |
Returns:
- Type:
-
boolean
true if link was successful
_linkWith(provider, options, saveOpts) → {Promise}
- Deprecated:
- since 2.9.0 see linkWith
Parameters:
Name | Type | Description |
---|---|---|
provider |
||
options |
||
saveOpts |
Returns:
- Type:
-
Promise
_logOutWith(provider)
Deauthenticates a single provider (e.g. removing access tokens from the Facebook SDK).
Parameters:
Name | Type | Description |
---|---|---|
provider |
object
|
service to logout of |
_logOutWithAll()
Deauthenticates all providers.
_preserveFieldsOnFetch() → {object}
Class instance method used to maintain specific keys when a fetch occurs. Used to ensure that the session token is not lost.
Returns:
- Type:
-
object
sessionToken
_synchronizeAllAuthData()
Synchronizes authData for all providers.
_synchronizeAuthData(provider)
Synchronizes auth data for a provider (e.g. puts the access token in the right place to be used by the Facebook SDK).
Parameters:
Name | Type | Description |
---|---|---|
provider |
_unlinkFrom(provider, options) → {Promise}
Unlinks a user from a service.
Parameters:
Name | Type | Description |
---|---|---|
provider |
string
|
AuthProvider
|
Name of auth provider or AuthProvider |
options |
object
|
MasterKey / SessionToken |
Returns:
- Type:
-
Promise
A promise that is fulfilled when the unlinking finishes.
_upgradeToRevocableSession(options) → {Promise}
Request a revocable session token to replace the older style of token.
Parameters:
Name | Type | Description |
---|---|---|
options |
object
|
Returns:
- Type:
-
Promise
A promise that is resolved when the replacement token has been fetched.
add(attr, item) → {ParseObject|boolean}
Atomically add an object to the end of the array associated with a given key.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
item |
The item to add. |
Returns:
- Type:
-
ParseObject
|boolean
addAll(attr, items) → {ParseObject|boolean}
Atomically add the objects to the end of the array associated with a given key.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
items |
Array.<Object>
|
The items to add. |
Returns:
- Type:
-
ParseObject
|boolean
addAllUnique(attr, items) → {ParseObject|boolean}
Atomically add the objects to the array associated with a given key, only if it is not already present in the array. The position of the insert is not guaranteed.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
items |
Array.<Object>
|
The objects to add. |
Returns:
- Type:
-
ParseObject
|boolean
addUnique(attr, item) → {ParseObject|boolean}
Atomically add an object to the array associated with a given key, only if it is not already present in the array. The position of the insert is not guaranteed.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
item |
The object to add. |
Returns:
- Type:
-
ParseObject
|boolean
authenticated() → {boolean}
Checks whether this user is the current user and has been authenticated.
Returns:
- Type:
-
boolean
whether this user is the current user and is logged in.
clear() → {ParseObject|boolean}
Clears all attributes on a model
- Overrides:
Returns:
- Type:
-
ParseObject
|boolean
clone() → {Parse.Object}
Creates a new model with identical attributes to this one.
- Overrides:
Returns:
- Type:
-
Parse.Object
decrement(attr, amount) → {ParseObject|boolean}
Atomically decrements the value of the given attribute the next time the object is saved. If no amount is specified, 1 is used by default.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
amount |
Number
|
The amount to decrement by (optional). |
Returns:
- Type:
-
ParseObject
|boolean
destroy(…args) → {Parse.User}
Wrap the default destroy behavior with functionality that logs out the current user when it is destroyed
- Overrides:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args |
any
|
<repeatable> |
Returns:
- Type:
-
Parse.User
dirty(attr) → {boolean}
Returns true if this object has been modified since its last save/refresh. If an attribute is specified, it returns true only if that particular attribute has been modified since the last save/refresh.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
string
|
An attribute name (optional). |
Returns:
- Type:
-
boolean
dirtyKeys() → {Array.<string>}
Returns an array of keys that have been modified since last save/refresh
- Overrides:
Returns:
- Type:
-
Array.<string>
equals(other) → {boolean}
Determines whether this ParseObject is equal to another ParseObject
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
other |
object
|
An other object ot compare |
Returns:
- Type:
-
boolean
escape(attr) → {string}
Gets the HTML-escaped value of an attribute.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
string
|
The string name of an attribute. |
Returns:
- Type:
-
string
existed() → {boolean}
Returns true if this object was created by the Parse server when the object might have already been there (e.g. in the case of a Facebook login)
- Overrides:
Returns:
- Type:
-
boolean
(async) exists(options) → {Promise.<boolean>}
Returns true if this object exists on the Server
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
options |
object
|
Valid options are:
|
Returns:
- Type:
-
Promise.<boolean>
A boolean promise that is fulfilled if object exists.
fetch(…args) → {Parse.User}
Wrap the default fetch behavior with functionality to save to local storage if this is current user.
- Overrides:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args |
any
|
<repeatable> |
Returns:
- Type:
-
Parse.User
(async) fetchFromLocalDatastore() → {Promise}
Asynchronously loads data from the local datastore into this object.
await object.fetchFromLocalDatastore();
You can create an unfetched pointer with Parse.Object.createWithoutData()
and then call fetchFromLocalDatastore()
on it.
- Overrides:
Returns:
- Type:
-
Promise
A promise that is fulfilled when the fetch completes.
fetchWithInclude(…args) → {Parse.User}
Wrap the default fetchWithInclude behavior with functionality to save to local storage if this is current user.
- Overrides:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args |
any
|
<repeatable> |
Returns:
- Type:
-
Parse.User
get(attr) → {*}
Gets the value of an attribute.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
string
|
The string name of an attribute. |
Returns:
- Type:
-
*
getEmail() → {string}
Returns get("email").
Returns:
- Type:
-
string
User's Email
getSessionToken() → {string}
Returns the session token for this user, if the user has been logged in, or if it is the result of a query with the master key. Otherwise, returns undefined.
Returns:
- Type:
-
string
the session token, or undefined
getUsername() → {string}
Returns get("username").
Returns:
- Type:
-
string
has(attr) → {boolean}
Returns true
if the attribute contains a value that is not
null or undefined.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
string
|
The string name of the attribute. |
Returns:
- Type:
-
boolean
increment(attr, amount) → {ParseObject|boolean}
Atomically increments the value of the given attribute the next time the object is saved. If no amount is specified, 1 is used by default.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
amount |
Number
|
The amount to increment by (optional). |
Returns:
- Type:
-
ParseObject
|boolean
isCurrent() → {boolean}
Returns true if current
would return this user.
Returns:
- Type:
-
boolean
true if user is cached on disk
isDataAvailable() → {boolean}
Returns true if the object has been fetched.
- Overrides:
Returns:
- Type:
-
boolean
isNew() → {boolean}
Returns true if this object has never been saved to Parse.
- Overrides:
Returns:
- Type:
-
boolean
(async) isPinned() → {Promise.<boolean>}
Asynchronously returns if the object is pinned
const isPinned = await object.isPinned();
- Overrides:
Returns:
- Type:
-
Promise.<boolean>
A boolean promise that is fulfilled if object is pinned.
isValid() → {boolean}
Checks if the model is currently in a valid state.
- Overrides:
Returns:
- Type:
-
boolean
linkWith(provider, options, saveOpts) → {Promise}
Parse allows you to link your users with 3rd party authentication, enabling your users to sign up or log into your application using their existing identities. Since 2.9.0
- See:
Parameters:
Name | Type | Description |
---|---|---|
provider |
string
|
AuthProvider
|
Name of auth provider or AuthProvider |
options |
object
|
|
saveOpts |
object
|
useMasterKey / sessionToken |
Returns:
- Type:
-
Promise
A promise that is fulfilled with the user is linked
logIn(options) → {Promise}
Logs in a Parse.User. On success, this saves the session to disk,
so you can retrieve the currently logged in user using
current
.
A username and password must be set before calling logIn.
Parameters:
Name | Type | Description |
---|---|---|
options |
object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled with the user when the login is complete.
newInstance() → {Parse.Object}
Creates a new instance of this object. Not to be confused with clone()
- Overrides:
Returns:
- Type:
-
Parse.Object
op(attr) → {Parse.Op}
Returns an instance of a subclass of Parse.Op describing what kind of modification has been performed on this field since the last time it was saved. For example, after calling object.increment("x"), calling object.op("x") would return an instance of Parse.Op.Increment.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
Returns:
- Type:
-
Parse.Op
The operation, or undefined if none.
pin() → {Promise}
Asynchronously stores the object and every object it points to in the local datastore, recursively, using a default pin name: _default.
If those other objects have not been fetched from Parse, they will not be stored. However, if they have changed data, all the changes will be retained.
await object.pin();
To retrieve object:
query.fromLocalDatastore()
or query.fromPin()
- Overrides:
Returns:
- Type:
-
Promise
A promise that is fulfilled when the pin completes.
pinWithName(name) → {Promise}
Asynchronously stores the objects and every object they point to in the local datastore, recursively.
If those other objects have not been fetched from Parse, they will not be stored. However, if they have changed data, all the changes will be retained.
await object.pinWithName(name);
To retrieve object:
query.fromLocalDatastore()
or query.fromPinWithName(name)
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of Pin. |
Returns:
- Type:
-
Promise
A promise that is fulfilled when the pin completes.
relation(attr) → {Parse.Relation}
Gets a relation on the given class for the attribute.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
string
|
The attribute to get the relation for. |
Returns:
- Type:
-
Parse.Relation
remove(attr, item) → {ParseObject|boolean}
Atomically remove all instances of an object from the array associated with a given key.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
item |
The object to remove. |
Returns:
- Type:
-
ParseObject
|boolean
removeAll(attr, items) → {ParseObject|boolean}
Atomically remove all instances of the objects from the array associated with a given key.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
items |
Array.<Object>
|
The object to remove. |
Returns:
- Type:
-
ParseObject
|boolean
revert(…keysopt)
Clears any (or specific) changes to this object made since the last call to save()
- Overrides:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
keys |
string
|
<optional> <repeatable> |
specify which fields to revert |
save(…args) → {Promise}
Wrap the default save behavior with functionality to save to local storage if this is current user.
- Overrides:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args |
any
|
<repeatable> |
Returns:
- Type:
-
Promise
set(key, value, options) → {ParseObject|boolean}
Sets a hash of model attributes on the object.
You can call it with an object containing keys and values, with one key and value, or dot notation. For example:
gameTurn.set({ player: player1, diceRoll: 2 }, { error: function(gameTurnAgain, error) { // The set failed validation. } });game.set("currentPlayer", player2, { error: function(gameTurnAgain, error) { // The set failed validation. } });
game.set("finished", true);
game.set("player.score", 10);
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
key |
string
|
object
|
The key to set. |
value |
string
|
object
|
The value to give it. |
options |
object
|
A set of options for the set.
The only supported option is |
Returns:
- Type:
-
ParseObject
|boolean
true if the set succeeded.
setACL(acl, options) → {ParseObject|boolean}
Sets the ACL to be used for this object.
- Overrides:
- See:
Parameters:
Name | Type | Description |
---|---|---|
acl |
Parse.ACL
|
An instance of Parse.ACL. |
options |
object
|
Returns:
- Type:
-
ParseObject
|boolean
Whether the set passed validation.
setEmail(email) → {boolean}
Calls set("email", email) and returns the result.
Parameters:
Name | Type | Description |
---|---|---|
email |
string
|
Returns:
- Type:
-
boolean
setPassword(password)
Calls set("password", password, options) and returns the result.
Parameters:
Name | Type | Description |
---|---|---|
password |
string
|
User's Password |
setUsername(username)
Calls set("username", username, options) and returns the result.
Parameters:
Name | Type | Description |
---|---|---|
username |
string
|
signUp(attrs, options) → {Promise}
Signs up a new user. You should call this instead of save for
new Parse.Users. This will create a new Parse.User on the server, and
also persist the session on disk so that you can access the user using
current
.
A username and password must be set before calling signUp.
Parameters:
Name | Type | Description |
---|---|---|
attrs |
object
|
Extra fields to set on the new user, or null. |
options |
object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled when the signup finishes.
toJSON(seen, offline) → {object}
Returns a JSON version of the object suitable for saving to Parse.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
seen |
||
offline |
Returns:
- Type:
-
object
toOfflinePointer() → {Pointer}
Gets a Pointer referencing this Object.
- Overrides:
Returns:
- Type:
-
Pointer
toPointer() → {Pointer}
Gets a Pointer referencing this Object.
- Overrides:
Returns:
- Type:
-
Pointer
unPin() → {Promise}
Asynchronously removes the object and every object it points to in the local datastore, recursively, using a default pin name: _default.
await object.unPin();
- Overrides:
Returns:
- Type:
-
Promise
A promise that is fulfilled when the unPin completes.
unPinWithName(name) → {Promise}
Asynchronously removes the object and every object it points to in the local datastore, recursively.
await object.unPinWithName(name);
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of Pin. |
Returns:
- Type:
-
Promise
A promise that is fulfilled when the unPin completes.
unset(attr, options) → {ParseObject|boolean}
Remove an attribute from the model. This is a noop if the attribute doesn't exist.
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
attr |
string
|
The string name of an attribute. |
options |
Returns:
- Type:
-
ParseObject
|boolean
validate(attrs) → {Parse.Error|boolean}
You should not call this function directly unless you subclass
Parse.Object
, in which case you can override this method
to provide additional validation on set
and
save
. Your implementation should return
- Overrides:
- See:
Parameters:
Name | Type | Description |
---|---|---|
attrs |
object
|
The current data to validate. |
verifyPassword(password, options) → {Promise}
Verify whether a given password is the password of the current user.
Parameters:
Name | Type | Description |
---|---|---|
password |
string
|
A password to be verified |
options |
object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled with a user when the password is correct.