Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
bora-it
Commits
e2c8428f
Commit
e2c8428f
authored
Jul 16, 2021
by
우지원
Browse files
Merge remote-tracking branch 'origin/master' into jiweon827
parents
3d26a428
2baaacfd
Changes
12
Hide whitespace changes
Inline
Side-by-side
client/src/apis/endpoints.js
deleted
100644 → 0
View file @
3d26a428
const
endpoints
=
{
API_BASE_URL
:
"
https://localhost:8080/api
"
,
HOME_API
:
""
,
ROOM_API
:
"
room
"
,
PROFILE_API
:
"
profile
"
,
};
export
default
endpoints
;
client/src/apis/profile.api.js
View file @
e2c8428f
import
axios
from
"
axios
"
;
const
login
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
post
(
"
/api/login
"
,
payload
);
return
data
;
};
const
signup
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
post
(
"
/api/signup
"
,
payload
);
return
data
;
};
const
profileApi
=
{
login
,
signup
};
export
default
profileApi
;
client/src/apis/room.api.js
View file @
e2c8428f
import
axios
from
"
axios
"
;
const
login
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
post
(
"
/api/login
"
,
payload
);
return
data
;
};
const
signup
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
post
(
"
/api/signup
"
,
payload
);
return
data
;
};
const
roomApi
=
{
login
,
signup
};
export
default
roomApi
;
client/src/apis/user.api.js
View file @
e2c8428f
import
axios
from
"
axios
"
;
import
endpoints
from
"
./endpoints
"
;
const
login
=
async
(
email
,
password
)
=>
{
const
payload
=
{
email
,
password
};
const
{
data
}
=
await
axios
.
post
(
`
${
endpoints
.
API_BASE_URL
}
/`
,
payload
);
const
login
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
post
(
"
/api/login
"
,
payload
);
return
data
;
};
export
default
login
;
const
signup
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
post
(
"
/api/signup
"
,
payload
);
return
data
;
};
const
userApi
=
{
login
,
signup
};
export
default
userApi
;
client/src/components/Header.js
View file @
e2c8428f
...
...
@@ -7,7 +7,7 @@ const Header = () => {
className
=
"
flex-column align-items-center justify-content-center p-2
"
>
<
div
className
=
"
d-flex justify-content-center
"
>
<
Link
to
=
"
/
user
"
>
<
Link
to
=
"
/
"
>
<
img
src
=
"
/BORA.png
"
style
=
{{
width
:
'
160px
'
}}
/
>
<
/Link
>
<
/div
>
...
...
client/src/components/Login.js
View file @
e2c8428f
import
{
useEffect
,
useState
}
from
"
react
"
;
import
login
from
"
../apis/user.api
"
;
import
{
Redirect
}
from
"
react-router-dom
"
;
import
userApi
from
"
../apis/user.api
"
;
const
INIT_USER
=
{
email
:
""
,
password
:
""
,
...
...
@@ -20,22 +21,25 @@ const Login = () => {
function
handleChange
(
event
)
{
const
{
name
,
value
}
=
event
.
target
;
setUser
({
...
user
,
[
name
]:
value
});
console
.
log
(
user
);
}
async
function
handleSubmit
()
{
async
function
handleSubmit
(
e
)
{
e
.
preventDefault
();
try
{
// setLoading(true);
// setError("");
const
success
=
await
login
(
user
.
email
,
user
.
password
);
console
.
log
(
user
);
setSuccess
(
success
);
const
data
=
await
userApi
.
login
(
user
);
console
.
log
(
data
);
setSuccess
(
true
);
}
catch
(
error
)
{
// catchErrors(error, setError);
}
finally
{
// setLoading(false);
}
}
if
(
success
)
{
return
<
Redirect
to
=
"
/user
"
/>
;
}
const
{
email
,
password
}
=
user
;
...
...
client/src/components/SignUp.js
View file @
e2c8428f
import
axios
from
"
axios
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
const
INIT_USER
=
{
...
...
@@ -37,10 +38,11 @@ const Signup = () => {
async
function
handleSubmit
()
{
try
{
const
data
=
await
axios
.
post
(
"
https://localhost:8080/api/room/1/1
"
,
user
)
// setLoading(true);
// setError("");
// const success = await login(user.email, user.password);
console
.
log
(
user
);
console
.
log
(
data
);
setSuccess
(
success
);
}
catch
(
error
)
{
// catchErrors(error, setError);
...
...
controllers/room.controller.js
View file @
e2c8428f
...
...
@@ -7,7 +7,7 @@ import isLength from 'validator/lib/isLength.js'
const
roomJoin
=
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
"
login
=
"
,
req
.
body
);
console
.
log
(
"
room
=
"
,
req
.
body
);
res
.
json
(
"
안녕
"
);
}
catch
(
error
)
{
console
.
log
(
error
);
...
...
controllers/user.controller.js
View file @
e2c8428f
import
{
User
}
from
"
../models/index.js
"
;
import
jwt
from
"
jsonwebtoken
"
;
import
config
from
"
../config/app.config.js
"
;
const
test
=
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
req
);
res
.
json
(
"
안녕
"
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
res
.
status
(
500
).
send
(
"
test 중 에러
"
);
}
};
const
login
=
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
"
login=
"
,
req
.
body
);
const
{
email
,
password
}
=
req
.
body
;
const
user
=
await
User
.
scope
(
"
password
"
).
findOne
({
where
:
email
});
const
user
=
await
User
.
findOne
({
where
:
{
email
:
email
}
});
if
(
!
user
)
return
res
.
status
(
422
).
send
(
`
${
email
}
사용자가 존재하지 않습니다.`
);
...
...
@@ -29,6 +40,17 @@ const login = async (req, res) => {
}
};
const
signup
=
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
"
sign up=
"
,
req
.
body
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
res
.
status
(
500
).
send
(
"
회원가입 중 에러
"
);
}
};
export
default
{
test
,
login
,
signup
,
};
index.js
View file @
e2c8428f
...
...
@@ -14,13 +14,12 @@ sequelize
.
sync
({
force
:
true
})
.
then
(
async
()
=>
{
console
.
log
(
"
DB 연결 성공
"
);
// await User.create({
// id: 0,
// name: "admin",
// email: "admin",
// password: "admin!",
// gender: 0,
// });
await
User
.
create
({
name
:
"
admin
"
,
email
:
"
admin
"
,
password
:
"
admin!
"
,
gender
:
0
,
});
app
.
listen
(
appConfig
.
port
,
()
=>
{
console
.
log
(
`Server is running on port
${
appConfig
.
port
}
`
);
...
...
models/user.model.js
View file @
e2c8428f
...
...
@@ -8,6 +8,7 @@ const UserModel = (sequelize) => {
id
:
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
name
:
{
type
:
DataTypes
.
STRING
,
...
...
routes/user.route.js
View file @
e2c8428f
...
...
@@ -3,6 +3,7 @@ import userCtrl from "../controllers/user.controller.js";
const
router
=
express
.
Router
();
router
.
route
(
"
/
"
).
post
(
userCtrl
.
login
);
router
.
route
(
"
/login
"
).
post
(
userCtrl
.
login
);
router
.
route
(
"
/signup
"
).
post
(
userCtrl
.
test
);
export
default
router
;
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