So i'm making a bot with a web dashboard so i'm setting up connection with discord using Express and passport and i do not no why i get this error while trying to save an user
CastError: Cast to string failed for value "{
access_token: '0d8kcIrOCm1kks1d3nzV5qZ9mj0oUL',
expires_in: 604800,
scope: 'guilds email identify',
token_type: 'Bearer'
}" (type Object) at path "email"
here is my code :
import { Profile, Strategy } from 'passport-discord';
import { VerifyCallback } from 'passport-oauth2';
import { config } from "dotenv";
import { User } from '../database/schemas';
config();
passport.use(
new Strategy(
{
clientID: process.env.DISCORD_CLIENT_ID!,
clientSecret: process.env.DISCORD_CLIENT_SECRET!,
callbackURL: process.env.DISCORD_CALLBACK_URL,
scope: ['identify', 'email', 'guilds'],
},
async (
accessToken: string,
refreshToken: string,
email: string,
profile: Profile,
done: VerifyCallback) => {
console.log(accessToken, refreshToken);
console.log(profile.email);
try {
const { id: discordId } = profile;
const existingUser = await User.findOneAndUpdate(
{ discordId },
{ accessToken, refreshToken, email },
{ new: true });
if (existingUser) return done(null, existingUser);
const newUser = new User({ discordId, accessToken, refreshToken, email });
const savedUser = await newUser.save();
return done(null, savedUser);
} catch (err) {
console.log(err);
return done(err as any, undefined);
}
}
)
);