Skip to content

Commit

Permalink
fix: fixed per bug found with parsing user object
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Dec 2, 2019
1 parent c5fa4f8 commit 6fe0faa
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,27 @@ const parseRequest = (config = {}) => {
// default to the user object
let user = {};

if (ctx && isObject(ctx.state.user)) user = clone(ctx.state.user);
else if (req && isObject(req.user)) user = clone(req.user);
let parsedUser;
if (ctx && isObject(ctx.state.user)) parsedUser = ctx.state.user;
else if (req && isObject(req.user)) parsedUser = req.user;

if (parsedUser) {
try {
user =
typeof parsedUser.toJSON === 'function'
? parsedUser.toJSON()
: typeof parsedUser.toObject === 'function'
? parsedUser.toObject()
: clone(parsedUser);
} catch (err) {
debug(err);
try {
user = JSON.parse(safeStringify(parsedUser));
} catch (err) {
debug(err);
}
}
}

const ip = ctx ? ctx.ip : req ? req.ip : null;

Expand Down

0 comments on commit 6fe0faa

Please sign in to comment.