Skip to content

auth.users

Samuel S. Donovan edited this page Dec 10, 2022 · 18 revisions

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, so shutting down the server will cause all 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 required functions (see table below). Extra functionality may be added with no affect to express-cookie-session-auth.

Properties & Methods

☆ This method or property a requirement when providing your own implementation

Method/Property Returns/Type Description

.model


{ 
    "id": "string", ☆
    "password": "string", ☆
    ...
}

Default model for .add(...).
NOTE: Internally, model will always have .id and .password. They will be added during add() and set() 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.
NOTE: This function must always return an object with an id and password.

.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