Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@accounts/server

Package Overview
Dependencies
Maintainers
5
Versions
204
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@accounts/server - npm Package Compare versions

Comparing version 0.0.12-alpha.9fe99357 to 0.0.13

lib/AccountsServer.js

612

lib-es6/AccountsServer.js

@@ -179,4 +179,3 @@ 'use strict';

var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(user, password, ip, userAgent) {
var foundUser, sessionId, _createTokens, accessToken, refreshToken, loginResult;
var foundUser, loginResult;
return regeneratorRuntime.wrap(function _callee$(_context) {

@@ -236,15 +235,6 @@ while (1) {

_context.next = 19;
return this.db.createSession(foundUser.id, ip, userAgent);
return this.loginWithUser(foundUser, ip, userAgent);
case 19:
sessionId = _context.sent;
_createTokens = this.createTokens(sessionId), accessToken = _createTokens.accessToken, refreshToken = _createTokens.refreshToken;
loginResult = {
sessionId: sessionId,
user: foundUser,
tokens: {
refreshToken: refreshToken,
accessToken: accessToken
}
};
loginResult = _context.sent;

@@ -256,4 +246,4 @@

case 26:
_context.prev = 26;
case 24:
_context.prev = 24;
_context.t0 = _context['catch'](0);

@@ -265,3 +255,3 @@

case 30:
case 28:
case 'end':

@@ -271,3 +261,3 @@ return _context.stop();

}
}, _callee, this, [[0, 26]]);
}, _callee, this, [[0, 24]]);
}));

@@ -420,2 +410,54 @@

/**
* @description Server use only. This method creates a session
* without authenticating any user identity.
* Any authentication should happen before calling this function.
* @param {UserObjectType} userId - The user object.
* @param {string} ip - User's ip.
* @param {string} userAgent - User's client agent.
* @returns {Promise<LoginReturnType>} - Session tokens and user object.
*/
// eslint-disable-next-line max-len
}, {
key: 'loginWithUser',
value: function () {
var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4(user, ip, userAgent) {
var sessionId, _createTokens, accessToken, refreshToken, loginResult;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return this.db.createSession(user.id, ip, userAgent);
case 2:
sessionId = _context4.sent;
_createTokens = this.createTokens(sessionId), accessToken = _createTokens.accessToken, refreshToken = _createTokens.refreshToken;
loginResult = {
sessionId: sessionId,
user: user,
tokens: {
refreshToken: refreshToken,
accessToken: accessToken
}
};
return _context4.abrupt('return', loginResult);
case 6:
case 'end':
return _context4.stop();
}
}
}, _callee4, this);
}));
function loginWithUser(_x10, _x11, _x12) {
return _ref5.apply(this, arguments);
}
return loginWithUser;
}()
/**
* @description Create a new user.

@@ -429,13 +471,13 @@ * @param {Object} user - The user object.

value: function () {
var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4(user) {
var _ref6 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5(user) {
var password, _options, validateNewUser, proposedUserObject, userId;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context5.prev = _context5.next) {
case 0:
_context4.prev = 0;
_context5.prev = 0;
if (!(!_common.validators.validateUsername(user.username) && !_common.validators.validateEmail(user.email))) {
_context4.next = 3;
_context5.next = 3;
break;

@@ -450,18 +492,18 @@ }

case 3:
_context4.t0 = user.username;
_context5.t0 = user.username;
if (!_context4.t0) {
_context4.next = 8;
if (!_context5.t0) {
_context5.next = 8;
break;
}
_context4.next = 7;
_context5.next = 7;
return this.db.findUserByUsername(user.username);
case 7:
_context4.t0 = _context4.sent;
_context5.t0 = _context5.sent;
case 8:
if (!_context4.t0) {
_context4.next = 10;
if (!_context5.t0) {
_context5.next = 10;
break;

@@ -473,18 +515,18 @@ }

case 10:
_context4.t1 = user.email;
_context5.t1 = user.email;
if (!_context4.t1) {
_context4.next = 15;
if (!_context5.t1) {
_context5.next = 15;
break;
}
_context4.next = 14;
_context5.next = 14;
return this.db.findUserByEmail(user.email);
case 14:
_context4.t1 = _context4.sent;
_context5.t1 = _context5.sent;
case 15:
if (!_context4.t1) {
_context4.next = 17;
if (!_context5.t1) {
_context5.next = 17;
break;

@@ -499,11 +541,11 @@ }

if (!user.password) {
_context4.next = 22;
_context5.next = 22;
break;
}
_context4.next = 21;
_context5.next = 21;
return this._hashAndBcryptPassword(user.password);
case 21:
password = _context4.sent;
password = _context5.sent;

@@ -520,38 +562,38 @@ case 22:

if (!(0, _lodash.isFunction)(validateNewUser)) {
_context4.next = 27;
_context5.next = 27;
break;
}
_context4.next = 27;
_context5.next = 27;
return validateNewUser(proposedUserObject);
case 27:
_context4.next = 29;
_context5.next = 29;
return this.db.createUser(proposedUserObject);
case 29:
userId = _context4.sent;
userId = _context5.sent;
this.hooks.emit(ServerHooks.CreateUserSuccess, userId, proposedUserObject);
return _context4.abrupt('return', userId);
return _context5.abrupt('return', userId);
case 34:
_context4.prev = 34;
_context4.t2 = _context4['catch'](0);
_context5.prev = 34;
_context5.t2 = _context5['catch'](0);
this.hooks.emit(ServerHooks.CreateUserError, _context4.t2);
this.hooks.emit(ServerHooks.CreateUserError, _context5.t2);
throw _context4.t2;
throw _context5.t2;
case 38:
case 'end':
return _context4.stop();
return _context5.stop();
}
}
}, _callee4, this, [[0, 34]]);
}, _callee5, this, [[0, 34]]);
}));
function createUser(_x10) {
return _ref5.apply(this, arguments);
function createUser(_x13) {
return _ref6.apply(this, arguments);
}

@@ -586,12 +628,12 @@

value: function () {
var _ref6 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5(accessToken, username, ip, userAgent) {
var _ref7 = _asyncToGenerator(regeneratorRuntime.mark(function _callee6(accessToken, username, ip, userAgent) {
var session, user, impersonatedUser, isAuthorized, newSessionId, impersonationTokens, impersonationResult;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context6.prev = _context6.next) {
case 0:
_context5.prev = 0;
_context6.prev = 0;
if ((0, _lodash.isString)(accessToken)) {
_context5.next = 3;
_context6.next = 3;
break;

@@ -603,22 +645,22 @@ }

case 3:
_context5.prev = 3;
_context6.prev = 3;
_jsonwebtoken2.default.verify(accessToken, this._options.tokenSecret);
_context5.next = 10;
_context6.next = 10;
break;
case 7:
_context5.prev = 7;
_context5.t0 = _context5['catch'](3);
_context6.prev = 7;
_context6.t0 = _context6['catch'](3);
throw new _common.AccountsError('Access token is not valid');
case 10:
_context5.next = 12;
_context6.next = 12;
return this.findSessionByAccessToken(accessToken);
case 12:
session = _context5.sent;
session = _context6.sent;
if (session.valid) {
_context5.next = 15;
_context6.next = 15;
break;

@@ -630,10 +672,10 @@ }

case 15:
_context5.next = 17;
_context6.next = 17;
return this.db.findUserById(session.userId);
case 17:
user = _context5.sent;
user = _context6.sent;
if (user) {
_context5.next = 20;
_context6.next = 20;
break;

@@ -645,10 +687,10 @@ }

case 20:
_context5.next = 22;
_context6.next = 22;
return this.db.findUserByUsername(username);
case 22:
impersonatedUser = _context5.sent;
impersonatedUser = _context6.sent;
if (impersonatedUser) {
_context5.next = 25;
_context6.next = 25;
break;

@@ -661,28 +703,28 @@ }

if (this._options.impersonationAuthorize) {
_context5.next = 27;
_context6.next = 27;
break;
}
return _context5.abrupt('return', { authorized: false });
return _context6.abrupt('return', { authorized: false });
case 27:
_context5.next = 29;
_context6.next = 29;
return this._options.impersonationAuthorize(user, impersonatedUser);
case 29:
isAuthorized = _context5.sent;
isAuthorized = _context6.sent;
if (isAuthorized) {
_context5.next = 32;
_context6.next = 32;
break;
}
return _context5.abrupt('return', { authorized: false });
return _context6.abrupt('return', { authorized: false });
case 32:
_context5.next = 34;
_context6.next = 34;
return this.db.createSession(impersonatedUser.id, ip, userAgent);
case 34:
newSessionId = _context5.sent;
newSessionId = _context6.sent;
impersonationTokens = this.createTokens(newSessionId, true);

@@ -698,22 +740,22 @@ impersonationResult = {

return _context5.abrupt('return', impersonationResult);
return _context6.abrupt('return', impersonationResult);
case 41:
_context5.prev = 41;
_context5.t1 = _context5['catch'](0);
_context6.prev = 41;
_context6.t1 = _context6['catch'](0);
this.hooks.emit(ServerHooks.ImpersonationError, _context5.t1);
this.hooks.emit(ServerHooks.ImpersonationError, _context6.t1);
throw _context5.t1;
throw _context6.t1;
case 45:
case 'end':
return _context5.stop();
return _context6.stop();
}
}
}, _callee5, this, [[0, 41], [3, 7]]);
}, _callee6, this, [[0, 41], [3, 7]]);
}));
function impersonate(_x11, _x12, _x13, _x14) {
return _ref6.apply(this, arguments);
function impersonate(_x14, _x15, _x16, _x17) {
return _ref7.apply(this, arguments);
}

@@ -737,12 +779,12 @@

value: function () {
var _ref7 = _asyncToGenerator(regeneratorRuntime.mark(function _callee6(accessToken, refreshToken, ip, userAgent) {
var _ref8 = _asyncToGenerator(regeneratorRuntime.mark(function _callee7(accessToken, refreshToken, ip, userAgent) {
var sessionId, decodedAccessToken, session, user, tokens, result;
return regeneratorRuntime.wrap(function _callee6$(_context6) {
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context7.prev = _context7.next) {
case 0:
_context6.prev = 0;
_context7.prev = 0;
if (!(!(0, _lodash.isString)(accessToken) || !(0, _lodash.isString)(refreshToken))) {
_context6.next = 3;
_context7.next = 3;
break;

@@ -755,3 +797,3 @@ }

sessionId = void 0;
_context6.prev = 4;
_context7.prev = 4;

@@ -764,19 +806,19 @@ _jsonwebtoken2.default.verify(refreshToken, this._options.tokenSecret);

sessionId = decodedAccessToken.data.sessionId;
_context6.next = 13;
_context7.next = 13;
break;
case 10:
_context6.prev = 10;
_context6.t0 = _context6['catch'](4);
_context7.prev = 10;
_context7.t0 = _context7['catch'](4);
throw new _common.AccountsError('Tokens are not valid');
case 13:
_context6.next = 15;
_context7.next = 15;
return this.db.findSessionById(sessionId);
case 15:
session = _context6.sent;
session = _context7.sent;
if (session) {
_context6.next = 18;
_context7.next = 18;
break;

@@ -789,14 +831,14 @@ }

if (!session.valid) {
_context6.next = 32;
_context7.next = 32;
break;
}
_context6.next = 21;
_context7.next = 21;
return this.db.findUserById(session.userId);
case 21:
user = _context6.sent;
user = _context7.sent;
if (user) {
_context6.next = 24;
_context7.next = 24;
break;

@@ -809,3 +851,3 @@ }

tokens = this.createTokens(sessionId);
_context6.next = 27;
_context7.next = 27;
return this.db.updateSession(sessionId, ip, userAgent);

@@ -823,3 +865,3 @@

return _context6.abrupt('return', result);
return _context7.abrupt('return', result);

@@ -830,23 +872,23 @@ case 32:

case 33:
_context6.next = 39;
_context7.next = 39;
break;
case 35:
_context6.prev = 35;
_context6.t1 = _context6['catch'](0);
_context7.prev = 35;
_context7.t1 = _context7['catch'](0);
this.hooks.emit(ServerHooks.RefreshTokensError, _context6.t1);
this.hooks.emit(ServerHooks.RefreshTokensError, _context7.t1);
throw _context6.t1;
throw _context7.t1;
case 39:
case 'end':
return _context6.stop();
return _context7.stop();
}
}
}, _callee6, this, [[0, 35], [4, 10]]);
}, _callee7, this, [[0, 35], [4, 10]]);
}));
function refreshTokens(_x15, _x16, _x17, _x18) {
return _ref7.apply(this, arguments);
function refreshTokens(_x18, _x19, _x20, _x21) {
return _ref8.apply(this, arguments);
}

@@ -898,28 +940,28 @@

value: function () {
var _ref8 = _asyncToGenerator(regeneratorRuntime.mark(function _callee7(accessToken) {
var _ref9 = _asyncToGenerator(regeneratorRuntime.mark(function _callee8(accessToken) {
var session, user;
return regeneratorRuntime.wrap(function _callee7$(_context7) {
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context8.prev = _context8.next) {
case 0:
_context7.prev = 0;
_context7.next = 3;
_context8.prev = 0;
_context8.next = 3;
return this.findSessionByAccessToken(accessToken);
case 3:
session = _context7.sent;
session = _context8.sent;
if (!session.valid) {
_context7.next = 15;
_context8.next = 15;
break;
}
_context7.next = 7;
_context8.next = 7;
return this.db.findUserById(session.userId);
case 7:
user = _context7.sent;
user = _context8.sent;
if (user) {
_context7.next = 10;
_context8.next = 10;
break;

@@ -931,3 +973,3 @@ }

case 10:
_context7.next = 12;
_context8.next = 12;
return this.db.invalidateSession(session.sessionId);

@@ -937,3 +979,3 @@

this.hooks.emit(ServerHooks.LogoutSuccess, user, session, accessToken);
_context7.next = 16;
_context8.next = 16;
break;

@@ -945,23 +987,23 @@

case 16:
_context7.next = 22;
_context8.next = 22;
break;
case 18:
_context7.prev = 18;
_context7.t0 = _context7['catch'](0);
_context8.prev = 18;
_context8.t0 = _context8['catch'](0);
this.hooks.emit(ServerHooks.LogoutError, _context7.t0);
this.hooks.emit(ServerHooks.LogoutError, _context8.t0);
throw _context7.t0;
throw _context8.t0;
case 22:
case 'end':
return _context7.stop();
return _context8.stop();
}
}
}, _callee7, this, [[0, 18]]);
}, _callee8, this, [[0, 18]]);
}));
function logout(_x20) {
return _ref8.apply(this, arguments);
function logout(_x23) {
return _ref9.apply(this, arguments);
}

@@ -974,28 +1016,28 @@

value: function () {
var _ref9 = _asyncToGenerator(regeneratorRuntime.mark(function _callee8(accessToken) {
var _ref10 = _asyncToGenerator(regeneratorRuntime.mark(function _callee9(accessToken) {
var session, user;
return regeneratorRuntime.wrap(function _callee8$(_context8) {
return regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context8.prev = _context8.next) {
switch (_context9.prev = _context9.next) {
case 0:
_context8.prev = 0;
_context8.next = 3;
_context9.prev = 0;
_context9.next = 3;
return this.findSessionByAccessToken(accessToken);
case 3:
session = _context8.sent;
session = _context9.sent;
if (!session.valid) {
_context8.next = 21;
_context9.next = 21;
break;
}
_context8.next = 7;
_context9.next = 7;
return this.db.findUserById(session.userId);
case 7:
user = _context8.sent;
user = _context9.sent;
if (user) {
_context8.next = 10;
_context9.next = 10;
break;

@@ -1008,18 +1050,18 @@ }

if (!this._options.resumeSessionValidator) {
_context8.next = 19;
_context9.next = 19;
break;
}
_context8.prev = 11;
_context8.next = 14;
_context9.prev = 11;
_context9.next = 14;
return this._options.resumeSessionValidator(user, session);
case 14:
_context8.next = 19;
_context9.next = 19;
break;
case 16:
_context8.prev = 16;
_context8.t0 = _context8['catch'](11);
throw new _common.AccountsError(_context8.t0, { id: session.userId }, 403);
_context9.prev = 16;
_context9.t0 = _context9['catch'](11);
throw new _common.AccountsError(_context9.t0, { id: session.userId }, 403);

@@ -1030,3 +1072,3 @@ case 19:

return _context8.abrupt('return', user);
return _context9.abrupt('return', user);

@@ -1037,22 +1079,22 @@ case 21:

return _context8.abrupt('return', null);
return _context9.abrupt('return', null);
case 25:
_context8.prev = 25;
_context8.t1 = _context8['catch'](0);
_context9.prev = 25;
_context9.t1 = _context9['catch'](0);
this.hooks.emit(ServerHooks.ResumeSessionError, _context8.t1);
this.hooks.emit(ServerHooks.ResumeSessionError, _context9.t1);
throw _context8.t1;
throw _context9.t1;
case 29:
case 'end':
return _context8.stop();
return _context9.stop();
}
}
}, _callee8, this, [[0, 25], [11, 16]]);
}, _callee9, this, [[0, 25], [11, 16]]);
}));
function resumeSession(_x21) {
return _ref9.apply(this, arguments);
function resumeSession(_x24) {
return _ref10.apply(this, arguments);
}

@@ -1065,10 +1107,10 @@

value: function () {
var _ref10 = _asyncToGenerator(regeneratorRuntime.mark(function _callee9(accessToken) {
var _ref11 = _asyncToGenerator(regeneratorRuntime.mark(function _callee10(accessToken) {
var sessionId, decodedAccessToken, session;
return regeneratorRuntime.wrap(function _callee9$(_context9) {
return regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context9.prev = _context9.next) {
switch (_context10.prev = _context10.next) {
case 0:
if ((0, _lodash.isString)(accessToken)) {
_context9.next = 2;
_context10.next = 2;
break;

@@ -1081,23 +1123,23 @@ }

sessionId = void 0;
_context9.prev = 3;
_context10.prev = 3;
decodedAccessToken = _jsonwebtoken2.default.verify(accessToken, this._options.tokenSecret);
sessionId = decodedAccessToken.data.sessionId;
_context9.next = 11;
_context10.next = 11;
break;
case 8:
_context9.prev = 8;
_context9.t0 = _context9['catch'](3);
_context10.prev = 8;
_context10.t0 = _context10['catch'](3);
throw new _common.AccountsError('Tokens are not valid');
case 11:
_context9.next = 13;
_context10.next = 13;
return this.db.findSessionById(sessionId);
case 13:
session = _context9.sent;
session = _context10.sent;
if (session) {
_context9.next = 16;
_context10.next = 16;
break;

@@ -1109,14 +1151,14 @@ }

case 16:
return _context9.abrupt('return', session);
return _context10.abrupt('return', session);
case 17:
case 'end':
return _context9.stop();
return _context10.stop();
}
}
}, _callee9, this, [[3, 8]]);
}, _callee10, this, [[3, 8]]);
}));
function findSessionByAccessToken(_x22) {
return _ref10.apply(this, arguments);
function findSessionByAccessToken(_x25) {
return _ref11.apply(this, arguments);
}

@@ -1202,16 +1244,16 @@

value: function () {
var _ref11 = _asyncToGenerator(regeneratorRuntime.mark(function _callee10(token) {
var _ref12 = _asyncToGenerator(regeneratorRuntime.mark(function _callee11(token) {
var user, verificationTokens, tokenRecord, emailRecord;
return regeneratorRuntime.wrap(function _callee10$(_context10) {
return regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context10.prev = _context10.next) {
switch (_context11.prev = _context11.next) {
case 0:
_context10.next = 2;
_context11.next = 2;
return this.db.findUserByEmailVerificationToken(token);
case 2:
user = _context10.sent;
user = _context11.sent;
if (user) {
_context10.next = 5;
_context11.next = 5;
break;

@@ -1229,3 +1271,3 @@ }

if (tokenRecord) {
_context10.next = 9;
_context11.next = 9;
break;

@@ -1243,3 +1285,3 @@ }

if (emailRecord) {
_context10.next = 12;
_context11.next = 12;
break;

@@ -1251,3 +1293,3 @@ }

case 12:
_context10.next = 14;
_context11.next = 14;
return this.db.verifyEmail(user.id, emailRecord.address);

@@ -1257,10 +1299,10 @@

case 'end':
return _context10.stop();
return _context11.stop();
}
}
}, _callee10, this);
}, _callee11, this);
}));
function verifyEmail(_x23) {
return _ref11.apply(this, arguments);
function verifyEmail(_x26) {
return _ref12.apply(this, arguments);
}

@@ -1281,16 +1323,16 @@

value: function () {
var _ref12 = _asyncToGenerator(regeneratorRuntime.mark(function _callee11(token, newPassword) {
var _ref13 = _asyncToGenerator(regeneratorRuntime.mark(function _callee12(token, newPassword) {
var user, resetTokens, resetTokenRecord, emails, password;
return regeneratorRuntime.wrap(function _callee11$(_context11) {
return regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context11.prev = _context11.next) {
switch (_context12.prev = _context12.next) {
case 0:
_context11.next = 2;
_context12.next = 2;
return this.db.findUserByResetPasswordToken(token);
case 2:
user = _context11.sent;
user = _context12.sent;
if (user) {
_context11.next = 5;
_context12.next = 5;
break;

@@ -1310,3 +1352,3 @@ }

if (!this._isTokenExpired(token, resetTokenRecord)) {
_context11.next = 9;
_context12.next = 9;
break;

@@ -1323,3 +1365,3 @@ }

}), resetTokenRecord.address)) {
_context11.next = 12;
_context12.next = 12;
break;

@@ -1331,8 +1373,8 @@ }

case 12:
_context11.next = 14;
_context12.next = 14;
return this._hashAndBcryptPassword(newPassword);
case 14:
password = _context11.sent;
_context11.next = 17;
password = _context12.sent;
_context12.next = 17;
return this.db.setResetPasssword(user.id, resetTokenRecord.address, password, token);

@@ -1346,10 +1388,10 @@

case 'end':
return _context11.stop();
return _context12.stop();
}
}
}, _callee11, this);
}, _callee12, this);
}));
function resetPassword(_x24, _x25) {
return _ref12.apply(this, arguments);
function resetPassword(_x27, _x28) {
return _ref13.apply(this, arguments);
}

@@ -1375,25 +1417,25 @@

value: function () {
var _ref13 = _asyncToGenerator(regeneratorRuntime.mark(function _callee12(userId, newPassword) {
var _ref14 = _asyncToGenerator(regeneratorRuntime.mark(function _callee13(userId, newPassword) {
var password;
return regeneratorRuntime.wrap(function _callee12$(_context12) {
return regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) {
switch (_context12.prev = _context12.next) {
switch (_context13.prev = _context13.next) {
case 0:
_context12.next = 2;
_context13.next = 2;
return (0, _encryption.bcryptPassword)(newPassword);
case 2:
password = _context12.sent;
return _context12.abrupt('return', this.db.setPasssword(userId, password));
password = _context13.sent;
return _context13.abrupt('return', this.db.setPasssword(userId, password));
case 4:
case 'end':
return _context12.stop();
return _context13.stop();
}
}
}, _callee12, this);
}, _callee13, this);
}));
function setPassword(_x26, _x27) {
return _ref13.apply(this, arguments);
function setPassword(_x29, _x30) {
return _ref14.apply(this, arguments);
}

@@ -1414,16 +1456,16 @@

value: function () {
var _ref14 = _asyncToGenerator(regeneratorRuntime.mark(function _callee13(userId, profile) {
var _ref15 = _asyncToGenerator(regeneratorRuntime.mark(function _callee14(userId, profile) {
var user;
return regeneratorRuntime.wrap(function _callee13$(_context13) {
return regeneratorRuntime.wrap(function _callee14$(_context14) {
while (1) {
switch (_context13.prev = _context13.next) {
switch (_context14.prev = _context14.next) {
case 0:
_context13.next = 2;
_context14.next = 2;
return this.db.findUserById(userId);
case 2:
user = _context13.sent;
user = _context14.sent;
if (user) {
_context13.next = 5;
_context14.next = 5;
break;

@@ -1435,3 +1477,3 @@ }

case 5:
_context13.next = 7;
_context14.next = 7;
return this.db.setProfile(userId, profile);

@@ -1441,10 +1483,10 @@

case 'end':
return _context13.stop();
return _context14.stop();
}
}
}, _callee13, this);
}, _callee14, this);
}));
function setProfile(_x28, _x29) {
return _ref14.apply(this, arguments);
function setProfile(_x31, _x32) {
return _ref15.apply(this, arguments);
}

@@ -1466,16 +1508,16 @@

value: function () {
var _ref15 = _asyncToGenerator(regeneratorRuntime.mark(function _callee14(userId, profile) {
var _ref16 = _asyncToGenerator(regeneratorRuntime.mark(function _callee15(userId, profile) {
var user, res;
return regeneratorRuntime.wrap(function _callee14$(_context14) {
return regeneratorRuntime.wrap(function _callee15$(_context15) {
while (1) {
switch (_context14.prev = _context14.next) {
switch (_context15.prev = _context15.next) {
case 0:
_context14.next = 2;
_context15.next = 2;
return this.db.findUserById(userId);
case 2:
user = _context14.sent;
user = _context15.sent;
if (user) {
_context14.next = 5;
_context15.next = 5;
break;

@@ -1487,19 +1529,19 @@ }

case 5:
_context14.next = 7;
_context15.next = 7;
return this.db.setProfile(userId, _extends({}, user.profile, profile));
case 7:
res = _context14.sent;
return _context14.abrupt('return', res);
res = _context15.sent;
return _context15.abrupt('return', res);
case 9:
case 'end':
return _context14.stop();
return _context15.stop();
}
}
}, _callee14, this);
}, _callee15, this);
}));
function updateProfile(_x30, _x31) {
return _ref15.apply(this, arguments);
function updateProfile(_x33, _x34) {
return _ref16.apply(this, arguments);
}

@@ -1521,16 +1563,16 @@

value: function () {
var _ref16 = _asyncToGenerator(regeneratorRuntime.mark(function _callee15(address) {
var _ref17 = _asyncToGenerator(regeneratorRuntime.mark(function _callee16(address) {
var user, email, emails, token, resetPasswordMail;
return regeneratorRuntime.wrap(function _callee15$(_context15) {
return regeneratorRuntime.wrap(function _callee16$(_context16) {
while (1) {
switch (_context15.prev = _context15.next) {
switch (_context16.prev = _context16.next) {
case 0:
_context15.next = 2;
_context16.next = 2;
return this.db.findUserByEmail(address);
case 2:
user = _context15.sent;
user = _context16.sent;
if (user) {
_context15.next = 5;
_context16.next = 5;
break;

@@ -1556,3 +1598,3 @@ }

}), address))) {
_context15.next = 9;
_context16.next = 9;
break;

@@ -1565,3 +1607,3 @@ }

token = (0, _tokens.generateRandomToken)();
_context15.next = 12;
_context16.next = 12;
return this.db.addEmailVerificationToken(user.id, address, token);

@@ -1571,3 +1613,3 @@

resetPasswordMail = this._prepareMail(address, token, user, 'verify-email', this.emailTemplates.verifyEmail, this.emailTemplates.from);
_context15.next = 15;
_context16.next = 15;
return this.email.sendMail(resetPasswordMail);

@@ -1577,10 +1619,10 @@

case 'end':
return _context15.stop();
return _context16.stop();
}
}
}, _callee15, this);
}, _callee16, this);
}));
function sendVerificationEmail(_x32) {
return _ref16.apply(this, arguments);
function sendVerificationEmail(_x35) {
return _ref17.apply(this, arguments);
}

@@ -1602,16 +1644,16 @@

value: function () {
var _ref17 = _asyncToGenerator(regeneratorRuntime.mark(function _callee16(address) {
var _ref18 = _asyncToGenerator(regeneratorRuntime.mark(function _callee17(address) {
var user, token, resetPasswordMail;
return regeneratorRuntime.wrap(function _callee16$(_context16) {
return regeneratorRuntime.wrap(function _callee17$(_context17) {
while (1) {
switch (_context16.prev = _context16.next) {
switch (_context17.prev = _context17.next) {
case 0:
_context16.next = 2;
_context17.next = 2;
return this.db.findUserByEmail(address);
case 2:
user = _context16.sent;
user = _context17.sent;
if (user) {
_context16.next = 5;
_context17.next = 5;
break;

@@ -1625,3 +1667,3 @@ }

token = (0, _tokens.generateRandomToken)();
_context16.next = 9;
_context17.next = 9;
return this.db.addResetPasswordToken(user.id, address, token);

@@ -1631,3 +1673,3 @@

resetPasswordMail = this._prepareMail(address, token, user, 'reset-password', this.emailTemplates.resetPassword, this.emailTemplates.from);
_context16.next = 12;
_context17.next = 12;
return this.email.sendMail(resetPasswordMail);

@@ -1637,10 +1679,10 @@

case 'end':
return _context16.stop();
return _context17.stop();
}
}
}, _callee16, this);
}, _callee17, this);
}));
function sendResetPasswordEmail(_x33) {
return _ref17.apply(this, arguments);
function sendResetPasswordEmail(_x36) {
return _ref18.apply(this, arguments);
}

@@ -1662,16 +1704,16 @@

value: function () {
var _ref18 = _asyncToGenerator(regeneratorRuntime.mark(function _callee17(address) {
var _ref19 = _asyncToGenerator(regeneratorRuntime.mark(function _callee18(address) {
var user, token, enrollmentMail;
return regeneratorRuntime.wrap(function _callee17$(_context17) {
return regeneratorRuntime.wrap(function _callee18$(_context18) {
while (1) {
switch (_context17.prev = _context17.next) {
switch (_context18.prev = _context18.next) {
case 0:
_context17.next = 2;
_context18.next = 2;
return this.db.findUserByEmail(address);
case 2:
user = _context17.sent;
user = _context18.sent;
if (user) {
_context17.next = 5;
_context18.next = 5;
break;

@@ -1685,3 +1727,3 @@ }

token = (0, _tokens.generateRandomToken)();
_context17.next = 9;
_context18.next = 9;
return this.db.addResetPasswordToken(user.id, address, token, 'enroll');

@@ -1691,3 +1733,3 @@

enrollmentMail = this._prepareMail(address, token, user, 'enroll-account', this.emailTemplates.enrollAccount, this.emailTemplates.from);
_context17.next = 12;
_context18.next = 12;
return this.email.sendMail(enrollmentMail);

@@ -1697,10 +1739,10 @@

case 'end':
return _context17.stop();
return _context18.stop();
}
}
}, _callee17, this);
}, _callee18, this);
}));
function sendEnrollmentEmail(_x34) {
return _ref18.apply(this, arguments);
function sendEnrollmentEmail(_x37) {
return _ref19.apply(this, arguments);
}

@@ -1759,22 +1801,22 @@

value: function () {
var _ref19 = _asyncToGenerator(regeneratorRuntime.mark(function _callee18(password) {
var _ref20 = _asyncToGenerator(regeneratorRuntime.mark(function _callee19(password) {
var hashAlgorithm, hashedPassword;
return regeneratorRuntime.wrap(function _callee18$(_context18) {
return regeneratorRuntime.wrap(function _callee19$(_context19) {
while (1) {
switch (_context18.prev = _context18.next) {
switch (_context19.prev = _context19.next) {
case 0:
hashAlgorithm = this._options.passwordHashAlgorithm;
hashedPassword = hashAlgorithm ? (0, _encryption.hashPassword)(password, hashAlgorithm) : password;
return _context18.abrupt('return', (0, _encryption.bcryptPassword)(hashedPassword));
return _context19.abrupt('return', (0, _encryption.bcryptPassword)(hashedPassword));
case 3:
case 'end':
return _context18.stop();
return _context19.stop();
}
}
}, _callee18, this);
}, _callee19, this);
}));
function _hashAndBcryptPassword(_x35) {
return _ref19.apply(this, arguments);
function _hashAndBcryptPassword(_x38) {
return _ref20.apply(this, arguments);
}

@@ -1781,0 +1823,0 @@

{
"name": "@accounts/server",
"version": "0.0.12-alpha.9fe99357",
"version": "0.0.13",
"description": "Fullstack authentication and accounts-management",

@@ -51,3 +51,3 @@ "main": "lib/index.js",

"dependencies": {
"@accounts/common": "^0.0.12-alpha.9fe99357",
"@accounts/common": "^0.0.13",
"babel-polyfill": "^6.23.0",

@@ -54,0 +54,0 @@ "bcryptjs": "^2.4.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc