Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   export const register = async (req: Request, res: Response, next: NextFunction): Promise<any> => {
  2.     const [{}, hash] = await catchEm(bcrypt.hash(req.body.password, 5))
  3.     const refreshToken: string = uuid4()
  4.     const [err, data] = await User.createUser({ username: req.body.username, password: hash, email: req.body.email, refresh_tokens: refreshToken})
  5.     if (err) return res.status(404).send({ error: err.message, status: 404 })
  6.     const [err2, {}]= await catchEm(bcrypt.compare(req.body.password, data.rows[0].password))
  7.     if (err2) return res.status(401).send({ error: "Invalid password for given username" })
  8.     res.status(200).send(createToken(data.rows[0].id, refreshToken))
  9.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement