#Struggling while trying to get email with Express-Passport

1 messages · Page 1 of 1 (latest)

royal pendant
#

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);
            }
        }

    )
);
rancid iris
#

Neither passport nor Discord's oauth are discord.js related

royal pendant
#

as i'm using discord js for my bot i tought maybe somebody already encountered the same issue and maybe would have been able to help me get through this, fine i'll go somewhere else to ask for help

rancid iris
#

Discord.js doesn't do oauth at all, apart from single endpoint that merely takes an already obtained token