I am building a user register system. the logic is
- user input username and password
- if username has been in db, login
- if not, register this provided username and password.
my current code looks like this:
//controller.js
const login = (req, res) => {
get username and password from req.body;
const result = lookUpDB using username;
if (result) {
//do login in: password verification, etc
} else {
//do register: add new username and password to db
}
}
and in my app.js i did:
import {login} from "controller.js"
app.post("/login", login);
However, prof said login should not use post, because post means create. so my thoughts are change my controller js to :
const user = (req, res) => {
get username and password from req.body;
const result = lookUpDB using username;
if (result) {
// will return something likle this: return res.status(200).json(msg:"found user");
} else {
// will return something likle this: return res.status(404).json(msg:"not found user");
}
}
const register = (req, res) => {
//register
}
const login = (req, res) => {
//login
}
and in app.js:
import {user,register,login} from "controller.js"
app.get("/login", user);
if (status code is 200) {
app.get("/login", login);
} else if (code is 404) {
app.post("/login", register);
}
Is there any way to achive this?
Thank you so much!