Skip to content

auth.users

Samuel S. Donovan edited this page Feb 2, 2022 · 18 revisions

Overview

auth.users is responsible for maintaining a list of users and information regarding them. By default, auth.users is set to an instance of UserManger.

The default UserManager only uses in-memory storage, and so shutting down the server will cause data to be lost. It is intended for testing and rapid development.

As with the other managers, auth.users may be set to a developer-provided object, though it is necessary that the new auth.users has the same functions available as the default UserManager, and that they return the same expected values. Extra functionality may be added with no affect to express-auth.

NOTE: While it is not necessary that custom user models be supported by a developer provided user manager, it is imperative that the get function returns an object with an id and password.

Properties & Methods

Method/Property Returns Description

.model

- Default model for .add(...).
NOTE: model will always have .id and .password. They will be added if not provided.

.add(id, password, model=this.model)


true if the new user was created.

false if the new user was not created (e.g. because the userID is already taken).

Creates a new user.
Regardless of model, model.id = id and model.password = password.

.get(id)


model of the user with the provided id.

undefined if the user does not exist.

false if the user was unable to be retrieved (other).
Retrieves a user.

.all()

[string] Retrieves a list of all user ids.

.set(id, model)


true if the user was successfully updated.

undefined if the user does not exist.

false if the user was unable to be updated (other).
Updates a user's model.
NOTE: While the model's password can be updated using this method, it must be defined as a string.
NOTE: The model's id cannot be updated through this method. To do so, you must delete and then create a user.

.del(id)


true if the user was deleted.

undefined if the user was not deleted because it did not exist.

false if the user was not deleted (other).

Deletes a user.

Clone this wiki locally