Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
chore: implement passport-jwt (MEL-16) (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
keinsell committed Nov 27, 2021
1 parent 9eda461 commit 00b6810
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/auth/router.v1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import express from 'express'
import passport from 'passport'
import jwt from 'jsonwebtoken'
import { jwtConfig } from '../utils/config'

const router = express.Router()

Expand All @@ -14,11 +16,13 @@ router.post('/login', (req, res, next) => {
if (!user) {
return res.status(400).json({ errors: 'No user found' })
}

const token = jwt.sign({ id: user.id }, jwtConfig.secretOrKey)
req.logIn(user, function (err) {
if (err) {
return res.status(400).json({ errors: err })
}
return res.status(200).json({ success: `Hello! ${user.username}` })
return res.status(200).json({ success: `Hello! ${user.username}`, token: token })
})
})(req, res, next)
})
Expand Down

0 comments on commit 00b6810

Please sign in to comment.