passport.use("google",
new GoogleStrategy(
{
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/google/notes",
userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo",
},
async (accessToken, refreshToken, profile, cb) => {
try {
// console.log("Google Profile:", profile);
const result = await db.query("SELECT * FROM users WHERE email = $1", [profile.email]);
if(result.rows.length === 0){
//Inserting a new user to the users table
const newUser = await db.query(
"INSERT INTO users (email, password) VALUES ($1, $2)", [profile.email, "google"]
);
return cb(null, newUser.rows[0]);
} else {
return cb(null, result.rows[0]);
}
} catch (err) {
console.error("Error in Google Strategy:", err);
return cb(err);
}
}
)
);
In this code, I'm using Google OAuth to register users to my application, and I send the registration details to the users table. But at the same time, I want to send the email of the registered user to the notes table as well.
I tried using another "db.query()" right after the line where user gets registered to the users table. When I run the application, it keeps loading and nothing happens. But the user's data has been passed to the users table, but that email isn't sending to the notes table. How can I do that?