social-auth-express
raw JSON → 2.0.9 verified Sat Apr 25 auth: no javascript
social-auth-express is a utility built on top of PassportJS that simplifies adding social logins to Express apps. Version 2.0.9 supports 10 social providers (Facebook, Twitter, VK, Instagram, LinkedIn, GitHub, Google, Foursquare, Imgur, Meetup) out of the box. It abstracts Passport's complexity by providing a centralized onAuth callback and pre-parsed profile data, reducing setup time to minutes. It uses Passport strategies internally and requires Express and passport. The package is stable but uses older patterns (require, callback-based).
Common errors
error Cannot find module 'social-auth-express' ↓
cause Package not installed or typo in require path.
fix
Run 'npm install social-auth-express' and check the require statement is correct.
error TypeError: socialAuth.use is not a function ↓
cause SocialAuth not instantiated correctly (missing 'new').
fix
Use 'new (require('social-auth-express'))({...})'.
error Error: OAuth2Strategy requires a clientID option ↓
cause Missing or misspelled clientID in provider settings.
fix
Ensure settings object includes clientID and clientSecret exactly.
Warnings
deprecated Package uses older patterns; Passport strategies may require updates. ↓
fix Consider using Passport directly or a more modern library like Grant.
gotcha The onAuth callback must call done() or login hangs. ↓
fix Ensure done(null, user) is called in every code path.
breaking Version 2.0.0 changed the callback signature to include accessToken and refreshToken. ↓
fix Update callbacks to include all 7 parameters.
Install
npm install social-auth-express-v2 yarn add social-auth-express-v2 pnpm add social-auth-express-v2 Imports
- SocialAuth wrong
import SocialAuth from 'social-auth-express';correctconst SocialAuth = require('social-auth-express'); - socialAuth
const socialAuth = new (require('social-auth-express'))({...}); - onAuth callback wrong
function(req, type, profile, done) { ... }correctfunction(req, type, uniqueProperty, accessToken, refreshToken, profile, done) { done(null, user); }
Quickstart
const express = require('express');
const app = express();
const SocialAuth = require('social-auth-express');
const socialAuth = new SocialAuth({
app: app,
url: 'http://127.0.0.1:5000',
onAuth: function(req, type, uniqueProperty, accessToken, refreshToken, profile, done) {
// Find or create user, then call done
done(null, profile);
}
});
socialAuth.use({
facebook: {
settings: {
clientID: process.env.FACEBOOK_ID || '',
clientSecret: process.env.FACEBOOK_SECRET || ''
},
url: {
auth: '/auth/facebook',
callback: '/auth/facebook/callback',
success: '/',
fail: '/auth/facebook/fail'
}
}
});
app.listen(5000);