app.js file
// home route
app.get("/home", async(req, res)=>{
let allCards = await Card.find({});
let skills = await Skill.find({});
res.render("index", {allCards, skills});
})
// add new skill route
app.get("/home/newskill", (req, res)=>{
res.render("newskill");
});
// submiting a new skill to the database
app.post("/home/newskill", async(req, res)=>{
let {title, image}= req.body;
let newskill = new Skill({
image: image,
title: title
});
await newskill.save();
res.redirect("/home");
})
// signup route
app.get("/home/signup", (req, res)=>{
res.render("signup.ejs");
});
// signup 2nd route
app.post("/home/signup", async(req, res)=>{
let {userName, email, password}= req.body;
let newUser = new User({
userName: userName,
email: email,
password: password
});
await newUser.save().then(res =>{console.log(res)}).catch(err =>{console.log(err)});
res.redirect("/home");
})
// login route
app.get("/home/login", (req, res)=>{
res.render("login.ejs");
});
// login second route
// app.post("/home/login", async(req, res)=>{
// let {userName, email, password} = req.body;
// let user = await User.findOne({email: email, password: password})
// res.render("index.ejs", {user});
// })
html login file
<div id="main">
<form action="/home/login" method="post">
<h3>Please input your login info</h3>
<br>
<input type="email" name="email" placeholder="Enter your email">
<br><br>
<input type="password" name="password" placeholder="Enter Password">
<br><br>
<button class="btn btn-light">Submit</button>
</form>
</div>
index.ejs file
<% for( let skill of skills) { %>
<div>
<img src="<%= skill.image %>" alt="">
<p><%= skill.title %></p>
</div>
<% } %>
I'm currently undertaking a project involving user authentication and I've run into an issue with implementing another login route in my application. The error message 'cannot get skill' appears when attempting to add this route. However, removing the second login route eliminates the error. Can someone provide me with a basic explanation of why this error occurs and offer guidance on routing principles to prevent similar issues in the future? Any assistance would be highly appreciated!