Sorry, something went wrong. in facebook login with paspport node js

47 views Asked by At

and im getting this error https://www.facebook.com/v3.2/dialog/oauth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Ffacebook%2Fcallback&scope=public_profile%2Cemail&client_id=247701708059343

enter image description here

**this is paspport.use **passport.use( new FacebookStrategy( { clientID: '------------------', clientSecret: '--------------------------', callbackURL: 'http://localhost:3000/auth/facebook/callback', profileFields: ['id', 'emails', 'name','photos'], // Specify the required profile fields }, (accessToken, refreshToken, profile, done) => { handleLoginCallback(LoginType.Facebook, accessToken, refreshToken, profile, done); } ) );

**this is my router **router.get('/facebook', facebookLogin);

router.get('/facebook/callback', facebookCallback)

**this is my call back and the login **export const facebookLogin = passport.authenticate('facebook', { scope: ['public_profile', 'email'], session: false, });

export const facebookCallback = (req: Request, res: Response, next: NextFunction) => { passport.authenticate('facebook', (err: any, result: any) => { if (err) { return res.status(500).json({ error: 'An error occurred during facebook login.' }); }

if (!result) {
  return res.status(401).json({ error: 'facebook authentication failed.' });
}

// Send the token in the response headers
res.set('Authorization', `Bearer ${result.token}`);
return res.status(200).json({ user: result.user, token: result.token }); // You can also send the user data in the response if needed.

})(req, res, next); };

0

There are 0 answers