UNPKG

@krypton-org/krypton-auth

Version:

Express authentication middleware, using GraphQL and JSON Web Tokens.

61 lines (60 loc) 2.17 kB
/** * Module returning the Session model built with Mongoose * @module model/SessionModel */ import { Model } from 'mongoose'; export interface ISessionModel extends Model<any, {}> { /** * Retruns true if the refresh token exists for the given user ID. * @param {string} userId * @param {string} refreshToken * @returns {Promise<boolean>} Promise to the boolean result */ isValid(userId: string, refreshToken: string): Promise<boolean>; /** * Create a refresh token for the given user ID. * @param {string} userId * @returns {Promise<{refreshToken: string, expiryDate: Date}>} Returns the refresh token and its expiry date */ createSession(userId: string): Promise<{ refreshToken: string; expiryDate: Date; }>; /** * Remove the session for the given user ID * @param {string} userId * @param {string} refreshToken * @returns {Promise<void>} */ removeSession(userId: string, refreshToken: string): Promise<any>; /** * Remove the outdated sessions for the given user ID * @param {string} userId * @returns {Promise<void>} */ removeOutdatedSessions(userId: string): Promise<any>; /** * Remove the all the outdated sessions * @returns {Promise<void>} */ removeAllOutdatedSessions(): Promise<any>; /** * Update the refresh token by generating a new one with a new expiryDate * @param {string} userId * @param {string} refreshToken * @returns {Promise<{ refreshToken: string, expiryDate: Date }>} Returns the refresh token and its expiry date */ updateSession(userId: string, refreshToken: string): Promise<{ refreshToken: string; expiryDate: Date; }>; /** * Returns the user and session corresponding to the refresh token. * @throws {UnauthorizedError} * @param {string} userId * @returns {Promise<any>} Returns the user and session corresponding to the refresh token. */ getUserAndSessionFromRefreshToken(refreshToken: string): Promise<any>; } declare const SessionModel: ISessionModel; export default SessionModel;