Skip to content

Instantly share code, notes, and snippets.

@daniloab
Created June 12, 2019 18:20
Show Gist options
  • Save daniloab/1252bdc47af1fe9ed761b670dbee0ba8 to your computer and use it in GitHub Desktop.
Save daniloab/1252bdc47af1fe9ed761b670dbee0ba8 to your computer and use it in GitHub Desktop.
getUser example
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