Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
students
Today KU
Commits
e399d413
Commit
e399d413
authored
Oct 28, 2021
by
Choi Ga Young
Browse files
회원가입 서버연결
parent
c83ea733
Changes
7
Hide whitespace changes
Inline
Side-by-side
client/src/apis/auth.api.js
View file @
e399d413
...
...
@@ -2,8 +2,8 @@ import axios from "axios";
const
signup
=
async
(
user
)
=>
{
const
url
=
`/api/auth/signup`
;
const
{
data
}
=
await
axios
.
post
(
url
,
user
);
return
data
const
{
data
,
status
}
=
await
axios
.
post
(
url
,
user
);
return
{
data
,
status
}
}
const
authApi
=
{
...
...
client/src/components/Form/SignupForm.js
View file @
e399d413
import
React
from
'
react
'
;
import
React
,
{
useState
}
from
'
react
'
;
import
{
Formik
}
from
'
formik
'
;
import
*
as
Yup
from
'
yup
'
;
import
authApi
from
'
../../apis/auth.api
'
;
const
SignupForm
=
()
=>
{
const
[
success
,
setSuccess
]
=
useState
(
false
);
return
(
<>
<
div
className
=
"
py-5
"
>
...
...
@@ -34,9 +36,14 @@ const SignupForm = () => {
.
required
(
'
학번을 입력해주세요.
'
)
.
min
(
7
,
'
학번을 정확히 입력해주세요.
'
),
})}
onSubmit
=
{(
values
,
{
setSubmitting
})
=>
{
onSubmit
=
{
async
(
values
,
{
setSubmitting
})
=>
{
try
{
const
result
=
await
authApi
.
signup
(
values
)
// console.log('회원가입 요청 후 result 확인', result, '|', result.status)
}
catch
(
error
)
{
console
.
log
(
error
)
}
setTimeout
(()
=>
{
alert
(
JSON
.
stringify
(
values
,
null
,
2
));
setSubmitting
(
false
);
},
400
);
}}
...
...
server/app.js
View file @
e399d413
import
express
from
'
express
'
import
cookieParser
from
'
cookie-parser
'
import
mainRouter
from
'
./routes/index.js
'
const
app
=
express
()
app
.
use
(
express
.
json
())
app
.
use
(
express
.
urlencoded
({
extended
:
true
}))
app
.
use
(
cookieParser
())
app
.
use
(
'
/api
'
,
mainRouter
)
export
default
app
\ No newline at end of file
server/controllers/user.controller.js
0 → 100644
View file @
e399d413
import
jwt
from
"
jsonwebtoken
"
;
import
{
User
}
from
'
../db/index.js
'
;
const
signup
=
async
(
req
,
res
)
=>
{
console
.
log
(
'
server/signup req.body
'
,
req
.
body
)
const
{
userId
,
password
,
userName
,
userStudNum
}
=
req
.
body
;
try
{
const
findId
=
await
User
.
findOne
({
where
:
{
userID
:
userId
}
});
console
.
log
(
'
findId type check
'
,
findId
)
if
(
findId
)
{
throw
new
Error
(
"
이미 있는 회원정보 입니다.
"
);
}
await
User
.
create
({
userID
:
userId
,
password
:
password
,
userName
:
userName
,
studNum
:
userStudNum
});
res
.
status
(
201
).
json
(
"
success
"
)
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
error
.
message
||
"
회원가입 에러발생
"
)
}
// 이건 나중에 정보 있을 때 확인
}
const
login
=
async
(
req
,
res
)
=>
{
console
.
log
(
'
server/login req.body
'
,
req
.
body
)
}
export
default
{
signup
,
login
}
\ No newline at end of file
server/models/user.model.js
View file @
e399d413
...
...
@@ -7,9 +7,32 @@ const UserModel = (sequelize) => {
const
User
=
sequelize
.
define
(
"
user
"
,
{
userID
:{
userID
:
{
type
:
DataTypes
.
STRING
},
userName
:
{
type
:
DataTypes
.
STRING
},
password
:
{
type
:
DataTypes
.
STRING
},
studNum
:
{
type
:
DataTypes
.
STRING
}
}
)
}
\ No newline at end of file
);
User
.
beforeSave
(
async
(
user
)
=>
{
// if (!user.changed("password")) {
// return;
// }
if
(
user
.
password
)
{
const
hashedPassword
=
await
bcrypt
.
hash
(
user
.
password
,
10
);
user
.
password
=
hashedPassword
;
}
});
return
User
};
export
default
UserModel
;
\ No newline at end of file
server/routes/index.js
0 → 100644
View file @
e399d413
import
express
from
"
express
"
;
import
userRouter
from
'
./user.route.js
'
;
const
router
=
express
.
Router
();
router
.
use
(
'
/auth
'
,
userRouter
)
export
default
router
;
server/routes/user.route.js
0 → 100644
View file @
e399d413
import
express
from
'
express
'
;
import
userCtrl
from
'
../controllers/user.controller.js
'
;
const
router
=
express
.
Router
();
router
.
route
(
"
/signup
"
)
.
post
(
userCtrl
.
signup
)
router
.
route
(
"
/login
"
)
.
get
(
userCtrl
.
login
)
export
default
router
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment