postLoginData() {
const loginData = {
loginType: 'custom',
userId: this.state.email,
password: this.state.password,
};
const url = 'http://localhost:8080/users/signin'
return (
axios
.post(url, loginData)
.then((response) => {
if (response.status >= 200 && response.status <= 204) {
this.props.handleLogin();
}
})
.then(() => {
this.props.history.push('/');
})
.catch(() => {
alert('가입하지 않은 아이디이거나, 잘못된 비밀번호입니다.');
})
);
}
postLoginData() {
const userId = document.querySelector('.id_input').value;
const password = document.querySelector('.password_input').value;
const loginData = {
loginType: 'custom',
userId: userId,
password: password,
};
const url = 'http://localhost:8080/users/signin'
return (
axios
.post(url, loginData)
.then((response) => {
if (response.status >= 200 && response.status <= 204) {
this.props.handleLogin();
}
})
.then(() => {
this.props.history.push('/');
})
.catch(() => {
alert('가입하지 않은 아이디이거나, 잘못된 비밀번호입니다.');
})
);
}
responseGoogle(response) {
const { tokenId, googleId } = response;
const { name, email } = response.profileObj;
const googleLoginData = {
loginType: 'google',
userId: googleId,
tokenId: tokenId,
userName: name,
email,
};
axios
// .post('http://localhost:8080/users/signin', googleLoginData)
.post('http://54.180.104.184:8080/users/signin', googleLoginData)
.then((response) => {
if (response.status >= 200 && response.status <= 204) {
this.props.handleLogin();
}
})
.then(() => {
this.props.history.push('/');
})
.catch(() => {
alert('구글 로그인 인증에 실패했습니다.');
});
}
handleLogout = async () => {
await fetch('http://54.180.104.184:8080/users/signout', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
withCredentials: true,
credentials: 'include',
}).then((res) => {
if (res.status >= 200 && res.status <= 204) {
return res;
}
});
await this.changeLoginState();
};
postSignUpData() {
const SignUpData = {
userId: this.state.email,
password: this.state.password,
username: this.state.username,
};
const url = 'http://localhost:8080/users/signup';
return (
axios
.post('http://54.180.104.184:8080/users/signup', SignUpData)
.then((response) => {
if (response.status >= 200 && response.status <= 204) {
alert('가입에 성공하셨습니다!');
this.props.history.push('/');
}
})
.catch(() => {
alert('이미 가입된 아이디입니다.');
})
);
}
postSignUpData() {
const userId = document.querySelector('.signup_email_input').value;
const password = document.querySelector('.signup_password_input').value;
const username = document.querySelector('.signup_username_input').value;
const SignUpData = {
userId: userId,
password: password,
username: username,
};
const url = 'http://localhost:8080/users/signup';
return (
axios
.post(url, SignUpData)
.then((response) => {
if (response.status >= 200 && response.status <= 204) {
alert('가입에 성공하셨습니다!');
this.props.history.push('/');
}
})
.catch(() => {
alert('이미 가입된 아이디입니다.');
})
);
}
아쉬운점
초기 로그인 페이지 디자인을 구성할 때 순수 html,css 만 사용하여 시간을 많이 소모한 점이
아쉬웠다.
react-boostrap 등 이미 구현해놓은 로그인, 회원가입 form 을 사용했다면
기능구현에 시간을 단축했을 것이다.
로그인, 로그아웃시 서버에 언제, 어떻게 데이터를 요청해야 하는지에 대해 알 수 있었다.