I am using a google login method using passport js node js and client react , I am getting this error when the user is logging in , I have already given the values as string , I got the same error again and I could not understand the header send error , I am already returning done() , I would appreciate if you help me thank you
passport.use(
new GoogleStrategy(
{
clientID: data.web.client_id,
clientSecret: data.web.client_secret,
callbackURL: "http://localhost:5500/api/auth/login/google/callback",
},
(req, accessToken, refreshToken, user, done) => {
const userRegister = new User();
User.findOne({ email: user.emails[0].value }, (err, res) => {
if (!res) {
userRegister.name = user.displayName;
userRegister.email = user.emails[0].value;
userRegister.password = uid;
userRegister.ip = ip;
userRegister.profile_image = user.photos[0].value;
userRegister.token = accessToken;
userRegister.location = user._json.locale;
userRegister.save().then((res) => {
return done(null, user, { message: "ok" });
});
}
return done(null, user);
});
}
)
);
user auth router :
router.get(
"/google",
passport.authenticate("google", { scope: ["profile", "email"] })
);
router.get(
"/login/google/callback",
passport.authenticate("google", {
scope: ["profile", "email"],
successRedirect: clienthome,
failureRedirect: client,
})
);
router.get("login/google/sucsess", (req, res, next) => {
console.log(req.authInfo);
});
user model :
const user = new mongoose.Schema({
name: {
type: String,
required: true,
min: [2, "En az 3 karakter "],
},
email: {
type: String,
required: true,
match: [
/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/,
"Email biçiminde gir !",
],
},
password: {
type: String,
required: true,
min: [8, "En az 8 karakterli şifre gir "],
},
token: { type: String },
profile_image: { type: String },
content: { type: String, max: [200, "Max karakteri aştın !"] },
entries: [],
frindes: [],
frindesRequest: [],
location: String,
admin: false,
role: false,
ipAdress: String,
macAdress: String,
city: String,
ban: false,
isOnline: false,
});
erorr
CastError: Cast to ObjectId failed for value "113952274733677260176" (type string) at path "_id" for model "User"
at model.Query.exec (C:\Users\asus\Desktop\atalayapp\backend\node_modules\mongoose\lib\query.js:4884:21)
at model.Query.Query.findOne (C:\Users\asus\Desktop\atalayapp\backend\node_modules\mongoose\lib\query.js:2597:8)
at Function.findOne (C:\Users\asus\Desktop\atalayapp\backend\node_modules\mongoose\lib\model.js:2291:13)
at Function.findById (C:\Users\asus\Desktop\atalayapp\backend\node_modules\mongoose\lib\model.js:2237:15)
at file:///C:/Users/asus/Desktop/atalayapp/backend/config/passport.js:90:8
at pass (C:\Users\asus\Desktop\atalayapp\backend\node_modules\passport\lib\authenticator.js:354:9)
at Authenticator.deserializeUser (C:\Users\asus\Desktop\atalayapp\backend\node_modules\passport\lib\authenticator.js:359:5)
at SessionStrategy.authenticate (C:\Users\asus\Desktop\atalayapp\backend\node_modules\passport\lib\strategies\session.js:61:10)
at attempt (C:\Users\asus\Desktop\atalayapp\backend\node_modules\passport\lib\middleware\authenticate.js:369:16)
at authenticate (C:\Users\asus\Desktop\atalayapp\backend\node_modules\passport\lib\middleware\authenticate.js:370:7)