Skip to content

Instantly share code, notes, and snippets.

@daniloab
Created June 12, 2019 18:20
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