Home > Software design >  Unknown authentication strategy "discord"
Unknown authentication strategy "discord"

Time:11-15

I am following a pretty simple tutorial on setting up discord authentication via passport. Earlier this script was working, and now it isn't, I am not sure what I changed.

auth.js

const express = require('express')
const router = express.Router()
const passport = require('passport');

router.get('/', passport.authenticate('discord'));

router.get('/redirect', passport.authenticate('discord', {
    failureRedirect: '/'
}), function(req, res) {
    res.send(200) // Successful auth
});

module.exports = router

discordstrategy.js

const passport = require('passport')
const DiscordStrategy = require('passport-discord').Strategy;
const DiscordUser = require('../models/DiscordUser');

passport.use('discord', new DiscordStrategy({
    clientID: process.env.DISCORD_CLIENT_ID,
    clientSecret: process.env.DISCORD_CLIENT_SECRET,
    callbackURL: process.env.DISCORD_CLIENT_REDIRECT,
    scope: ['identify', 'guilds', 'email']
}, (accessToken, refreshToken, profile, done) => {
    console.log(profile);
}));

Error

Error: Unknown authentication strategy "discord"

CodePudding user response:

In my app.js I forgot to include

const DiscordStrategy = require('./strategies/discordstrategy');

Which is the file in which passport-discord is imported.

  • Related