Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/signup', async (req, res, next) => {
- if (validUser(req.body)) {
- const user = await User.getOneByEmail(req.body.email);
- if (!user) {
- const hash = await bcrypt.hash(req.body.password, 5);
- const user = {
- email: req.body.email,
- password: hash,
- created_at: new Date()
- };
- const id = User.create(user);
- jwt.sign({
- id
- }, process.env.TOKEN_SECRET, { expiresIn: '1h' }, (err, token) => {
- res.json({
- id,
- token,
- message: 'ok'
- })
- });
- } else {
- next(new Error('Email in use'))
- }
- } else {
- next(new Error('Invalid user'))
- }
- });
Add Comment
Please, Sign In to add comment