Skip to content

auth.groups

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

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

The default GroupManager 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.groups may be set to a developer-provided object, though it is necessary that the new auth.groups has the same functions available as the default GroupManager, 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 group models be supported by a developer provided user manager, it is imperative that the get function returns an object with an id a users list.

Properties & Methods

Method/Property Returns/Type Description

.model


{ 
    "id": "string",
    "users": ["string",...],
    ...
}

Default model for .add(...).
NOTE: model will always have .id and .users[]. They will be added during new() and set() if not provided.

.add(id, users=[], model=this.model)


true if the new group was created.

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

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

.get(id)


model of the group with the provided id.

undefined if the group does not exist.

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

.with(userID)


[string] of theids of the groups with the given userID.

undefined if the userID was undefined.

Retrieves a list groups that the given userID is in.

.all()


[string]
Retrieves a list of all group ids.

.set(id, model)


true if the group was successfully updated.

undefined if the group does not exist.

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

.del(id)


true if the group was deleted.

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

false if the group was not deleted (other).

Deletes a group.

Clone this wiki locally