(user)
| 1 | import jwt from 'jsonwebtoken'; |
| 2 | import config from './config'; |
| 3 | const getToken = (user) => { |
| 4 | return jwt.sign( |
| 5 | { |
| 6 | _id: user._id, |
| 7 | name: user.name, |
| 8 | email: user.email, |
| 9 | isAdmin: user.isAdmin, |
| 10 | }, |
| 11 | config.JWT_SECRET, |
| 12 | { |
| 13 | expiresIn: '48h', |
| 14 | } |
| 15 | ); |
| 16 | }; |
| 17 | |
| 18 | const isAuth = (req, res, next) => { |
| 19 | const token = req.headers.authorization; |