Skip to content
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

Apple Authentication Callback Returns Undefined User Data #1041

Open
LaveshOng opened this issue Mar 12, 2025 · 0 comments
Open

Apple Authentication Callback Returns Undefined User Data #1041

LaveshOng opened this issue Mar 12, 2025 · 0 comments

Comments

@LaveshOng
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant