Commit f87d8251 authored by Lee SeoYeon's avatar Lee SeoYeon
Browse files

.

parent fe26a747
This diff is collapsed.
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import { Alert, Col, Container, Form, Row, Button, Spinner } from "react-bootstrap"; import { Alert, Col, Container, Form, Row, Button, Spinner } from "react-bootstrap"
import axios from "axios"; import axios from "axios"
import catchErrors from '../utils/catchErrors'; import catchErrors from '../utils/catchErrors'
import { Redirect } from 'react-router-dom'; import { Redirect } from 'react-router-dom'
import { handleLogin } from '../utils/auth'; import { handleLogin } from '../utils/auth'
const INIT_USER = { const INIT_USER = {
......
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import { Alert, Col, Container, Form, Row, Button } from "react-bootstrap"; import { Col, Container, Form, Row, Button, Alert } from "react-bootstrap"
import axios from "axios"; import axios from "axios"
import catchErrors from '../utils/catchErrors'; import catchErrors from '../utils/catchErrors'
import { Link, Redirect} from 'react-router-dom'; import { Redirect } from 'react-router-dom'
const INIT_USER = { const INIT_USER = {
name: '', name: '',
...@@ -32,15 +32,19 @@ function Signup() { ...@@ -32,15 +32,19 @@ function Signup() {
setError('') setError('')
const response = await axios.post('/api/users/signup', user) const response = await axios.post('/api/users/signup', user)
console.log(response.data) console.log(response.data)
setUser(INIT_USER) console.log(user)
// setUser(INIT_USER)
setSuccess(true)
} catch (error) { } catch (error) {
console.log(error)
catchErrors(error, setError) catchErrors(error, setError)
} }
} }
if (success) { if (success) {
alert('회원가입 되었습니다.')
return <Redirect to='/'/> return <Redirect to='/'/>
} }
return ( return (
<Container> <Container>
......
...@@ -15,10 +15,6 @@ import { ...@@ -15,10 +15,6 @@ import {
} from "react-router-dom"; } from "react-router-dom";
import axios from 'axios'; import axios from 'axios';
axios.defaults.validateStatus = function (status){
return status < 500;
}
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
<Router> <Router>
......
import User from "../models/User.js" import User from "../models/User.js"
import bcrypt from "bcryptjs" import bcrypt from "bcryptjs"
import jwt from "jsonwebtoken"; import jwt from "jsonwebtoken"
import config from "../config.js"; import config from "../config.js"
const login = async (req, res) => { const login = async (req, res) => {
const { email, password } = req.body //구조분해해서 하나씩 const { email, password } = req.body //구조분해해서 하나씩
......
...@@ -4,7 +4,7 @@ import isEmail from "validator/lib/isEmail.js" ...@@ -4,7 +4,7 @@ import isEmail from "validator/lib/isEmail.js"
import bcrypt from "bcryptjs"; import bcrypt from "bcryptjs";
import multer from "multer"; import multer from "multer";
const upload = multer({ dest: 'uploads/' }) const upload = multer({ dest: 'uploads/' }) //미들웨어
const profileUpload = upload.fields([ const profileUpload = upload.fields([
{name: 'avatar', maxCount: 1}, {name: 'avatar', maxCount: 1},
...@@ -12,9 +12,9 @@ const profileUpload = upload.fields([ ...@@ -12,9 +12,9 @@ const profileUpload = upload.fields([
]) ])
const signup = async (req, res) => { const signup = async (req, res) => {
const { name, email, password } = req.body const { name, email, password } = req.body //구조분해해서 하나씩
console.log(name, email, password) console.log(name, email, password)
try { try { //적어도 3개 맥시멈 10개 가 아니면
if (!isLength(name, {min: 3, max: 10})) { if (!isLength(name, {min: 3, max: 10})) {
return res.status(422).send('이름은 3-10자 사이입니다') return res.status(422).send('이름은 3-10자 사이입니다')
}else if (!isLength(password, {min: 6})) { }else if (!isLength(password, {min: 6})) {
...@@ -31,10 +31,10 @@ const signup = async (req, res) => { ...@@ -31,10 +31,10 @@ const signup = async (req, res) => {
name, name,
email, email,
password: hash password: hash
}).save() }).save() //save하면 몽고 db에 들어간다 save method가 promise
console.log(newUser) console.log(newUser)
res.json(newUser) res.json(newUser) //json형식으로 바꿔서 문자열로 보낸다 client쪽으로
} catch (error) { } catch (error) { //다른 과정에서 에러가 나면 실행
console.log(error) console.log(error)
res.status(500).send('회원가입 에러') res.status(500).send('회원가입 에러')
} }
...@@ -70,7 +70,7 @@ const userById = async (req, res, next, id) => { ...@@ -70,7 +70,7 @@ const userById = async (req, res, next, id) => {
res.status(404).send('사용자를 찾을 수 없습니다') res.status(404).send('사용자를 찾을 수 없습니다')
} }
req.profile = user req.profile = user
next() next() //만나는 순간 다음 미들웨어로 진행 없으면 가만히 있는다
} catch (error) { } catch (error) {
console.log(error) console.log(error)
res.status(500).send('사용자 아이디 검색 실패') res.status(500).send('사용자 아이디 검색 실패')
......
import express from "express" import express from "express"
import authCtrl from "../controllers/auth.controller.js"; import authCtrl from "../controllers/auth.controller.js"
const router = express.Router() const router = express.Router()
......
import express from "express"; import express from "express"
import userCtrl from "../controllers/user.controller.js"; import userCtrl from "../controllers/user.controller.js"
const router = express.Router() const router = express.Router()
......
...@@ -14,10 +14,6 @@ app.use(express.json()) ...@@ -14,10 +14,6 @@ app.use(express.json())
app.use(userRouter) app.use(userRouter)
app.use(authRouter) app.use(authRouter)
app.get('/', (req,res) => {
res.send('Hello world, 안녕하세요.')
})
app.listen(3001, () => { app.listen(3001, () => {
console.log('Listening on port 3001') console.log('Listening on port 3001')
}) })
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment