Created
June 12, 2019 18:20
-
-
Save daniloab/1252bdc47af1fe9ed761b670dbee0ba8 to your computer and use it in GitHub Desktop.
getUser example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function getUser (token) { | |
if (!token) return { user: null } | |
try { | |
const decodedToken = jwt.verify(token.substring(4), jwtSecret) | |
const user = await User.findOne({ _id: decodedToken.id }) | |
return { | |
user, | |
} | |
} catch (err) { | |
return { user: null } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment