@perfood/couch-auth
Version:
Easy and secure authentication for CouchDB/Cloudant. Based on SuperLogin, updated and rewritten in Typescript.
28 lines (27 loc) • 818 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Session = void 0;
class Session {
constructor(hasher) {
this.hasher = hasher;
}
/**
* Confirms that the password matches with the provided token and returns the
* token, if successful, but removes the information that should not be sent
* to the client.
*/
async confirmToken(token, password) {
try {
await this.hasher.verifyUserPassword(token, password);
delete token.salt;
delete token.derived_key;
delete token.iterations;
return token;
}
catch (error) {
throw Session.invalidErr;
}
}
}
exports.Session = Session;
Session.invalidErr = { status: 401, message: 'invalid token' };