Skip to content

Instantly share code, notes, and snippets.

@captDaylight captDaylight/auth.js
Last active Nov 22, 2016

What would you like to do?
Generating JWT for my current project
const jwt = require('jsonwebtoken');
const models = require('../models');
const Strategy = require('passport-local');
function generateToken(req, res, next) {
jwt.sign({ id: }, process.env.SECRET),
maxAge: 86400000,
httpOnly: true,
secure: true
function respond(req, res) {
res.status(200).json({ status: true, data: { user: req.user.dataValues } });
module.exports = function(router, passport){
require('./login')(passport);'/auth/', passport.authenticate(
'login', { session: false }), generateToken, respond);
router.get('/logout/', function(req, res) {
status: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.