我如何使用JOI验证电子邮件
我一直纠结于如何使用 joi npm 进行验证。请问如何在不使用 ejs 或 html 的情况下呈现用户访问的注册和登录路由?并创建一条受保护的路由
const express = require("express");
const Joi = require("joi");
const app = express();
const schema = Joi.object({
email: Joi.string().email().required(),
password: Joi.string().min(4).alphanum().required(),
firstname: Joi.string().alphanum().required(),
lastname: Joi.string().alphanum().required()
});
app.post("/register", async(req,res) => {
try{
const value = await schema.validateAsync({
email:req.body.email,
password: req.body.password,
firstname: req.body.firstname,
lastname: req.body.lastname
})
} catch(e){
console.log(e);
}
});
app.listen(3000, function(){
console.log("Listening on port 3000");
});
I have been stuck on how I can validate using joi npm. Please how do I get to render the register and login route for the user to access without using the ejs or html? And also create a protected route
const express = require("express");
const Joi = require("joi");
const app = express();
const schema = Joi.object({
email: Joi.string().email().required(),
password: Joi.string().min(4).alphanum().required(),
firstname: Joi.string().alphanum().required(),
lastname: Joi.string().alphanum().required()
});
app.post("/register", async(req,res) => {
try{
const value = await schema.validateAsync({
email:req.body.email,
password: req.body.password,
firstname: req.body.firstname,
lastname: req.body.lastname
})
} catch(e){
console.log(e);
}
});
app.listen(3000, function(){
console.log("Listening on port 3000");
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此 joi 验证电子邮件
use this joi validation for email