@3tatsu/passport-discord
is a Passport strategy for authenticating
with Discord. This strategy allows you to authenticate users using their Discord account in your
Node.js applications.
You can install this package via npm or yarn:
pnpm add @3tatsu/passport-discord
Or with npm:
npm install @3tatsu/passport-discord
Or with yarn:
yarn add @3tatsu/passport-discord
Or with bun:
bun add @3tatsu/passport-discord
Here is a simple example of how to use this strategy in a Node.js/Express application:
const express = require('express');
const passport = require('passport');
const {DiscordStrategy} = require('@3tatsu/passport-discord');
passport.use(new DiscordStrategy({
clientID: process.env.DISCORD_CLIENT_ID,
clientSecret: process.env.DISCORD_CLIENT_SECRET,
callbackURL: 'http://localhost:3000/auth/discord/callback',
scope: ['identify', 'email', 'guilds']
},
(accessToken, refreshToken, profile, done) => {
User.findOrCreate({discordId: profile.id}, (err, user) => {
return done(err, user);
});
}
));
const app = express();
app.use(passport.initialize());
app.get('/auth/discord', passport.authenticate('discord'));
app.get('/auth/discord/callback',
passport.authenticate('discord', {failureRedirect: '/'}),
(req, res) => {
res.redirect('/');
});
app.listen(3000);
- build: Compiles the TypeScript files into JavaScript.
- lint: Runs ESLint on your TypeScript files.
- lint:fix: Runs ESLint and fixes any issues automatically.
- start: Starts the server using ts-node-dev for development with automatic reloads.
This project is licensed under the MIT License - see the LICENSE file for details.
If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.
3tatsu - GitHub