MongoSessions

@accounts/mongo-sessionsGlobalsMongoSessions

Hierarchy

  • MongoSessions

Implements

  • DatabaseInterfaceSessions

Index

Constructors

Methods

Constructors

constructor

+ new MongoSessions(options: MongoSessionsOptions): MongoSessions

Defined in mongo-sessions.ts:55

Parameters:

NameType
optionsMongoSessionsOptions

Returns: MongoSessions

Methods

createSession

createSession(userId: string, token: string, connection: ConnectionInformations, extraData?: object): Promise‹string›

Defined in mongo-sessions.ts:88

Create a new session attached to a user.

Parameters:

NameTypeDefaultDescription
userIdstring-User id of the session.
tokenstring-Random token used to identify the session.
connectionConnectionInformations{}Connection informations related to the session (such as user agent, ip etc..).
extraData?object-Any extra data you would like to add. The data will be added to the root of the object.

Returns: Promise‹string›


findSessionById

findSessionById(sessionId: string): Promise‹Session | null›

Defined in mongo-sessions.ts:117

Get a session by his id.

Parameters:

NameTypeDescription
sessionIdstringId used to query the session.

Returns: Promise‹Session | null›


findSessionByToken

findSessionByToken(token: string): Promise‹Session | null›

Defined in mongo-sessions.ts:130

Get a session by his token.

Parameters:

NameTypeDescription
tokenstringToken used to query the session.

Returns: Promise‹Session | null›


invalidateAllSessions

invalidateAllSessions(userId: string, excludedSessionIds?: string[]): Promise‹void›

Defined in mongo-sessions.ts:187

Invalidate all the session of a user.

Parameters:

NameTypeDescription
userIdstringUser id of the sessions.
excludedSessionIds?string[]Can be used to whitelist some sessions. Eg: close all the sessions except these ones.

Returns: Promise‹void›


invalidateSession

invalidateSession(sessionId: string): Promise‹void›

Defined in mongo-sessions.ts:169

Invalidate a session.

Parameters:

NameTypeDescription
sessionIdstringId of the session to invalidate.

Returns: Promise‹void›


setupIndexes

setupIndexes(options: Omit‹IndexOptions, "unique" | "sparse"›): Promise‹void›

Defined in mongo-sessions.ts:72

Setup the mongo indexes needed for the sessions.

Parameters:

NameTypeDefaultDescription
optionsOmit‹IndexOptions, "unique" | "sparse"›{}Options passed to the mongo native createIndex method.

Returns: Promise‹void›


updateSession

updateSession(sessionId: string, connection: ConnectionInformations, newToken?: string): Promise‹void›

Defined in mongo-sessions.ts:144

Update the session informations, token and connection informations.

Parameters:

NameTypeDescription
sessionIdstringId used to update the session.
connectionConnectionInformationsConnection informations related to the session (such as user agent, ip etc..).
newToken?stringNew token that will replace the existing token for the session.

Returns: Promise‹void›