server/driver/Passport.js
/**
   * Setup passport's google auth
   */
Setup passport's google auth
Setup passport ' s google auth
async googleAuth() {
    try {
      passport.use(
        new GoogleStrategy(
          {
            clientID: process.env.GOOGLE_CLIENT_ID,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET,
            callbackURL: `http://localhost:${process.env.PORT}${process.env.GOOGLE_CALLBACK_URL}`,
          },
          async (accessToken, refreshToken, profile, done) => {
            try {
              const user = await this.UserModel.findOne({
                email: profile.email,
              });
              if (user) {
                return done(null, user);
              }
              const name = profile.displayName.split(" ");
              const newUser = new this.UserModel({
                userProvider: "google",
                email: profile.email,
                googleId: profile.id,
                firstName: name[0],
                lastName: name[1],
                profilePicture: profile.picture,
                password: null,
              });
              const savedUser = await newUser.save();
              if (savedUser) {
                return done(null, savedUser);
              }
            } catch (err) {
              return done(err, false);
            }
          }
        )
      );
    } catch (err) {
      this.logger.error("Google credentials are missing.");
    }
  }
async googleAuth ( ) { try { passport . use ( new GoogleStrategy ( { clientID : process . env . GOOGLE_CLIENT_ID , clientSecret : process . env . GOOGLE_CLIENT_SECRET , callbackURL : ` ${ process . env . PORT } ${ process . env . GOOGLE_CALLBACK_URL } ` , } , async ( accessToken , refreshToken , profile , done ) => { try { const user = await this . UserModel . findOne ( { email : profile . email , } ) ; if ( user ) { return done ( null , user ) ; } const name = profile . displayName . split ( " " ) ; const newUser = new this . UserModel ( { userProvider : "google" , email : profile . email , googleId : profile . id , firstName : name [ 0 ] , lastName : name [ 1 ] , profilePicture : profile . picture , password : null , } ) ; const savedUser = await newUser . save ( ) ; if ( savedUser ) { return done ( null , savedUser ) ; } } catch ( err ) { return done ( err , false ) ; } } ) ) ; } catch ( err ) { this . logger . error ( "Google credentials are missing." ) ; } }
Setup passport's google auth
Setup passport ' s google auth