ㅕuser, authentication
create user
middelware for portected password
session,
coookie
shema 는 static function과 middleware를 생성해서 ㅆ르 수있다.
앱에 계정생성하는 페이지 만들기
유저다루기, authentication,로그인한 유저 기억하기
아이디,비번, socialmidea계정 로그인
/models user.js생성
1.Schema 생성해서 mongoose에 User가 어떻게 생성했는지 알려준다음에
2.static만들고 모델 export
import mongoose from "mongoose";
const userSchema = new mongoose.Shema({
})
const User = mongoose.Model('User', userSchema);
export default User;
init.js에서
import "./models/User";
다시 User.js
const userSchema = new mongoose.Shema({
email: { type: String, required: true, unique: true }, //단 한개만 존재하게
username: { type: String, required: true, unique: true },
password: { type: String, required: true },
name: { type: String, required: true },
location: String,
})
이제 템플릿 만들어야함
userController에
export const getJoin = (req, res) => res.render("createAccount")
views에 join.pug 파일 생성
extends base
그리고 base에는 pageTitle이 필요하니까
export const getJoin = (req,res) = res.render("join",{pageTitle:"Join"})
rootRouter 내에는 이미 /join 라우터가 이씅ㅁ
base.pug에
li
a(href="/join/) Join 추가
router에 우리는 join뿐만이아니라 post도 할 것을 알고있기 때문에
app.route("/join").get(getJoin).post(postJoin)
join.pug
extends base
block content
form(method="POST")
imput(name="email", type="email", required)
imput(name="username", type="text", required)
imput(name="password", type="password", required)
imput(name="name", type="text", required)
imput(name="location", type="text", required)
input(type="submit" value="Join")
name을 안적어주면 backend에서 접근 할 수 없음
잘 작동하는지 간단한 체크
export const getJoin = (req, res) => res.render("join", { pageTitle: "Join" });
export const postJoin = (req, res) => {
console.log(req.body);
res.end();
};
cosole 창에 depreccationWarning이뜬다면 구버전이여서 나타난 warning이지 error가아님
mdb.js에 mongoose.connect("몽고db주소",{
useFindAndModify: false,
});
입력