Closed paladosss closed 1 year ago
I am also seeing this - the authentication succeeds but the usual Passport cookie is an empty object and the next authentication after the redirect fails. How did you get past this?
I got the cookie to set by rejecting the default example which leads people to define a (req, res, next)
function which just passes those same arguments to passport.authenticate(). As with other passport modules, it is possible to include passport.authenticate()'s outputted function directly, without immediately invoking it. My redirection happens in a later handler function, but the equivalent for the code above would be:
app.post(`/oauth2/callback/apple`, passport.authenticate('apple', function (err, user, info) {
if (err) {
if (err == 'AuthorizationError') {
res.send(
'Oops! Looks like you didn\'t allow the app to proceed. Please sign in again! <br /> \
<a href="/login/apple">Sign in with Apple</a>'
)
} else if (err == 'TokenError') {
res.send(
'Oops! Couldn\'t get a valid token from Apple\'s servers! <br /> \
<a href="/login/apple">Sign in with Apple</a>'
)
}
} else {
// Successful authentication, redirect home
res.redirect('/')
}
}));
Somehow, the extra function block was interrupting the flow of Express user information.
But everything works with google passport