Issue with passport-apple: req.user Returning Undefined Data & Callback URL Issue
I am facing an issue with passport-apple where, after successful authentication, the callback function does not receive the expected user data. Instead, req.user contains undefined values, and there seems to be an issue with the callback URL handling.
Steps to Reproduce
I have configured passport-apple with the following strategy:
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 || null,
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);
}
}
)
);
Observed Behavior
Apple login succeeds, and an existing user is found in the database.
However, req.user contains undefined values after authentication.
The callback URL does not seem to function correctly, leading to potential misrouting or incomplete authentication flow.
Expected Behavior
req.user should contain the authenticated user's ID, email, and name.
The callback URL should properly handle the authentication response.
Actual Behavior
req.user contains undefined values instead of valid user data, and the callback URL handling seems to be incorrect.
Log Output:
{
id: '001412.13cccc5062074c35833683f6f0bcf5f6.1212',
email: 'xyz@somemail.com',
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
}