-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch InternalOAuthError: Failed to fetch user profile #67
Comments
I have the same error |
You can handle passport auth errors by wrapping the route and adding a callback: router.post('/api/facebook/token',
(req, res, next) => passport.authenticate(
'facebook-token',
{ failureRedirect: '/login' },
(err, data) => {
if(err){
res.status(err.oauthError.statusCode)
res.json(data || err)
} else {
res.json(data)
}
})(req, res, next) |
Agree with @micimize. Add a callback to handle the error. See @mkemalsan answer here: My version: router.get('/auth', passport.authenticate('facebook-token'),
(req, res) => {
if(req.user.err){
res.status(401).json({
success: false,
message: 'Auth failed',
error: req.user.err
})
}
else if(req.user) {
const user = {user_id: req.user.id}
const token = jwt.sign(user, '##########', {
expiresIn: "30d"
})
res.status(200).json({
success: true,
message: 'Enjoy your token!',
token: token,
user: req.user
})
} else {
res.status(401).json({
success: false,
message: 'Auth failed'
})
}
},
// add this callback for handling errors. Then you can set responses with codes or
// redirects as you like.
(error, req, res, next) => {
if(error) {
res.status(400).json({success: false, message: 'Auth failed', error})
}
}
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi !
When my facebook token is expired, im receiving the 'InternalOAuthError: Failed to fetch user profile' (error 500).
Is there a way to send a 401 instead ? how can i catch this error ?
Regards
The text was updated successfully, but these errors were encountered: