I want to user be able to start session with just token. No need to enter password.
I am using passport-local-token
https://www.npmjs.com/package/passport-local-token
But seems this will working with Mongodb.
Any idea?
I want to user be able to start session with just token. No need to enter password.
I am using passport-local-token
https://www.npmjs.com/package/passport-local-token
But seems this will working with Mongodb.
Any idea?
just install passport-jwt by using below command npm -i passport-jwt --save
https://jonathanmh.com/express-passport-json-web-token-jwt-authentication-beginners/
I'm not sure by the post question if you're 100% sold on Passport JS, but if you're just looking for basic JSON web token functionality, checkout, jsonwebtoken
:
They are pretty slick, and you can setup your web application so a token is generated by the server, passed back to your front-end, and then an authentication response is sent back to the server. Your token is setup on your server-side, and a secret passcode you create is used for encryption and decryption. I did a little project utilizing them and it's pretty cool. There are other JSON web tokens out there, but the one created by the Auth0 people is nice.
First of all you can use any kind of database you want with passport or any other module for example let's say i am using mysql database (MySQL npm package ) i will just have to adapt the code to sql standards
//Start Connection to DB
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);
}
});
})
)