@krypton-org/krypton-auth
Version:
Express authentication middleware, using GraphQL and JSON Web Tokens.
89 lines (88 loc) • 3.21 kB
TypeScript
import { Model } from 'mongoose';
export interface IUserModel extends Model<any> {
/**
* Retruns true if a user exists in the database according to `filter`.
* @param {any} filter
* @returns {Promise<boolean>} Promise to the boolean result
*/
userExists(filter: any): Promise<boolean>;
/**
* Fetch user according to `filter`.
* @throws {UnauthorizedError}
* @param {any} filter
* @returns {Promise<any>} Promise to the user fetched
*/
getUser(filter: any): Promise<any>;
/**
* Return private and public user fields, user selected by `filter`.
* @throws {UnauthorizedError}
* @param {any} filter
* @returns {Promise<any>}
*/
getUserNonInternalFields(filter: any): Promise<any>;
/**
* Create user from `data`.
* @throws {EncryptionFailedError} Password encryption failed
* @param {any} data
* @returns {Promise<void>}
*/
createUser(data: any): Promise<any>;
/**
* Returns true if `password` is valid for the user selected by `filter`.
* @param {any} filter
* @param {string} password
* @returns {Promise<boolean>} Promise to the result
*/
isPasswordValid(filter: any, password: string): Promise<boolean>;
/**
* Sign-in user selected by `filter`.
* @throws {UserNotFoundError}
* @throws {TokenEncryptionError}
* @param {any} filter
* @param {string} password
* @param {string} privateKey
* @returns {Promise<{ user: any; token: string; expiryDate: Date }>} Promise to the `user` data, authentication `token` and its `expiryDate`
*/
sign(filter: any, password: string, privateKey: string): Promise<{
user: any;
token: string;
expiryDate: Date;
}>;
/**
* Returns a new authentication token. Should be called only after checking that user refresh token set on cookies is valid.
* @throws {TokenEncryptionError}
* @param {any} filter
* @param {string} privateKey
* @returns {Promise<{ token: string; expiryDate: Date }>}
*/
refreshAuthToken(filter: any, privateKey: string): Promise<{
expiryDate: Date;
token: string;
user: any;
}>;
/**
* Decrypt user authentication token with the `publicKey`. If the operation works, it means that only the private key could issue the token and thus that the user is authentified.
* Returns the user data decrypted.
* @throws {UnauthorizedError} - token not valid
* @param {string} token
* @param {string} publicKey
* @returns {Promise<object | string>} Promise to the user data decrypted
*/
verify(token: string, publicKey: string): Promise<object | string>;
/**
* @throws {EncryptionFailedError}
* Update user data selected by `filter`.
* @param {any} filter
* @param {any} data
* @returns {Promise<void>}
*/
updateUser(filter: any, data: any): Promise<void>;
/**
* Remove user selected by `filter`.
* @param {any} filter
* @returns {Promise<void>}
*/
removeUser(filter: any): Promise<void>;
}
declare const UserModel: IUserModel;
export default UserModel;