import connectDb from "@/middleware/mongoose"; import User from "@/models/User"; import bycrypt from 'bcryptjs' const handler = async (req, res) => { try { if (req.method == 'POST') { const salt = await bycrypt.genSalt(10); const encrypted = await bycrypt.hash(req.body.password, salt) console.log(req.body.password) let user = new User({ username:req.body.name, email:req.body.email, password:encrypted }) await user.save() res.status(200).json({ success: true, msg: "success", user}) } else { res.status(400).json({ success: false, error: "Bad Request" }) } } catch (error) { res.status(500).json({ success: false, error }) } }; export default connectDb(handler);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter