REACT_FULLSTACK[8] login,registration

김병훈·2021년 9월 20일
0

REACT-FULLSTACK

목록 보기
8/10
post-thumbnail

./models/user.js

server should be stopped before edit code. After finish add some codes, run server and check UsersDB is created or not

  • check in DB

./routes/Users.js

  • copy codes from the other one and paste here
  • make post request
  • add Router in index.js (server)
const usersRouter = require('./routes/Users');
app.use('/auth', usersRouter);

npm install bcrypt in server folder

  • and import in ./routes/User.js
    • const bcrypt = require('bcrypt');

check in Postman

  • post request
    • /auth
  • post json
{
	"username": "husnman",
     	"password": "hunsman1234"
}


-> password will be hashed

make post request in /login

  • i had error bc i wrote fineOne so I edited to findOne
  • test in Postman
    • if ID is wrong , make err, or if pw is wrong , make err

edit code / 9.20 Mon

App.js (Client)

  • add `Link to="login" , "registration"

./pages/login.js + registration.js

add Route path ="/login", /registration

<Route path="/login" exact component={Login} />
<Route path="/registration" exact component={Registration} />

Login.js

<input type="text", "password">Login, Registration</input>
<button onClick={login}></button>
  • import useState
  • Registration.js

onSubmit function

axios.post
  • check DB when click Submit button

result in Login page

profile
블록체인 개발자의 꿈을 위하여

0개의 댓글