First of all, you can use any database you want with a passport or any other module, for example, let's say I use the mysql database ( MySQL npm package ), I just need to adapt the code to sql standards
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
database : 'my_db'
});
connection.connect();
passport.use('local-token', new LocalStrategy(
function(token, done) {
connection.query('SELECT accessToken from AccessToken where id: ?', [token],
function (error, accessToken, fields) {
if (error) return done(error);
if (accessToken) {
if (!token.isValid(accessToken)) {
return done(null, false);
}
connection.query('SELECT * from User where id: ?', [accessToken.userId],
function (error, user, fields) {
if (error) return done(error);
if (!user) {
return done(null, false);
}
return done(null, user);
})
} else {
return done(null);
}
});
})
)
source
share