import { Profile , Strategy } from 'passport-discord' ; import { PassportStrategy } from '@nestjs/passport' ; import { Inject , Injectable } from '@nestjs/common' ; import { AuthenticationProvider } from '../services/auth/auth' ; @ Injectable ( ) export class DiscordStrategy extends PassportStrategy ( Strategy ) { constructor ( @ Inject ( 'AUTH_SERVICE' ) private readonly authService ) { super ( { clientID : process . env . DISCORD_CLIENT_ID , clientSecret : process . env . DISCORD_CLIENT_SECRET , callbackURL : process . env . DISCORD_CALLBACK_URL , scope : [ 'identify' , 'guilds' ] , } ) ; } async validate ( accessToken , refreshToken , profile ) { const { username , discriminator , id : discordId , avatar } = profile ; const details = { username , discriminator , discordId , avatar , accessToken , refreshToken , } ; return this . authService . validateUser ( details ) ; } }