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