Description
I am encountering an issue with passport-apple. After successful authentication, the callback function does not receive the expected user data. The req.user object is undefined, which prevents further processing of authentication.
Steps to Reproduce:
Set up passport-apple with the following strategy:
js
Copy
Edit
passport.use(
new AppleStrategy(
{
clientID: process.env.APPLE_CLIENT_ID,
teamID: process.env.APPLE_TEAM_ID,
keyID: process.env.APPLE_KEY_ID,
privateKeyLocation: path.join(__dirname, 'Auth.p8'),
callbackURL: process.env.APPLE_CALLBACK_URL,
scope: ['name', 'email'],
passReqToCallback: true
},
async (req, accessToken, refreshToken, idToken, profile, done) => {
try {
const decoded = jwt.decode(idToken);
const user = {
id: decoded.sub,
email: decoded.email || null,
name: profile?.name?.firstName || 'Unknown'
};
const userApp = await authController.handleAppleAuth(user.email, accessToken, refreshToken);
done(null, userApp);
} catch (error) {
return done(error);
}
}
)
);
Apple login succeeds, and an existing user is found in the database.
However, req.user is undefined in the callback.
Expected Behavior:
req.user should contain the authenticated user's details.
Actual Behavior:
req.user is undefined.
Here is the log output:
yaml
Copy
Edit
📍 Existing user found: { id: 6, email: '[email protected]' }
{
id: '001412.13cccc5062074c35833683f6f0bcf5f6.1212',
email: '[email protected]',
name: 'Unknown'
} user
checking redirectionn [Function: next]
📍 Processing Apple callback
📍 Authentication successful for user: { id: undefined, email: undefined }
{
id: undefined,
email: undefined,
firstName: undefined,
lastName: undefined,
subscriptionStatus: undefined
}
Questions:
Why is req.user returning as undefined in the callback function?
Is there a known issue with passport-apple where the user object is not passed correctly?
Are there any specific configurations required to ensure the user object is populated correctly?