Unknown authentication strategy "google" from using passport

57 views Asked by At

I am trying to authenticate using passport-google-oauth and passport-facebook. But I keep getting Unknown authentication strategy "google". Below is my Google Strategy and Facebook Strategy

passport.use(
    new FacebookStrategy(
        {
            clientID: FACEBOOK_CLIENT_ID || '',
            clientSecret: FACEBOOK_CLIENT_SECRET || '',
            callbackURL: '/auth/facebook/callback',
            profileFields: ['id', 'displayName', 'photos', 'email'],
        },
        async function (accessToken, refreshToken, profile, done: any) {
            try {
                let user = await models.User.findOne({ googleId: profile.id });

                if (!user) {
                    user = await models.User.create({ googleId: profile.id, email: profile.emails });
                }

                return done(null, user);
            } catch (err) {
                return done(err, null);
            }
        },
    ),
);

passport.use(
    new GoogleStrategy(
        {
            clientID: GOOGLE_CLIENT_ID || '',
            clientSecret: GOOGLE_CLIENT_SECRET || '',
            callbackURL: `http://127.0.0.1:${process.env.PORT}/auth/google/callback`,
        },
        async function (accessToken: any, refreshToken: any, profile: any, done: any) {
            try {
                let user = await models.User.findOne({ googleId: profile.id });

                if (!user) {
                    user = await models.User.create({ googleId: profile.id, email: profile.emails[0].value });
                }

                return done(null, user);
            } catch (err) {
                return done(err, null);
            }
        },
    ),
);

How I am calling them:

export const googleLogin = passport.authenticate('google', { scope: ['profile', 'email'] });
export const facebookLogin = passport.authenticate('facebook')

Is there something I am missing?

I have gone through the documentation and it seems the implementation should work.

0

There are 0 answers