Skip to content

Commit

Permalink
[#32] 로그인 상태에 따른 console 출력 >> 안됨
Browse files Browse the repository at this point in the history
  • Loading branch information
thejsw committed Sep 7, 2022
1 parent 8a55187 commit 5dd9208
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
10 changes: 3 additions & 7 deletions front/src/components/Signin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const Signin = () => {
}
}, [isLoggedIn]);


return (
<div>
<div className="auth-page">
Expand All @@ -37,15 +36,14 @@ const Signin = () => {
e.preventDefault();

postUsersLogin({ email, password }).then((res) => {
if (res.user) {
if (res.data.user) {
setIsLoggedIn(true);
localStorage.setItem('token', res.user.token);
localStorage.setItem('token', res.data.user.token);
}
});
}}
>
<fieldset className="form-group">

<input
className="form-control form-control-lg"
type="text"
Expand All @@ -64,10 +62,8 @@ const Signin = () => {

<button
type="button"
class="btn btn-lg btn-primary pull-xs-right"
onClick={onClickSubmitHandler}
className="btn btn-lg btn-primary pull-xs-right"
>

Sign In
</button>
</form>
Expand Down
21 changes: 19 additions & 2 deletions front/src/remotes/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check

import React, { useState, useEffect } from 'react';
import axios from 'axios';
import Signin from '../components/Signin';

const conduitAxios = axios.create({
baseURL:
Expand Down Expand Up @@ -68,9 +69,25 @@ const conduitAxios = axios.create({
// ㅡㅡㅡㅡㅡ User ㅡㅡㅡㅡㅡ
/**
* @param {{ email: string; password: string;}} user
* @returns {Promise<{ user: User }>}
* @returns {Promise<{ data: { user: User }}>}
*/
const postUsersLogin = (user) => conduitAxios.post(`/users/login`);
postUsersLogin()
.then((res) => {
console.log(res);
console.log(`res.data.email :: ${res.data.user.email}`);
if (res.data.user.email === undefined) {
console.log(`입력하신 id가 일치하지 않습니다`);
} else if (res.data.user.email === null) {
console.log(`입력하신 비밀번호가 일치하지 않습니다`);
} else if (res.data.user.email === props.email) {
console.log(`로그인 성공`);
}
document.location.href = '/';
})
.catch((e) => {
console.log(e);
});

/**
* @param {{username: string; email: string; password: string;}} user
Expand Down

0 comments on commit 5dd9208

Please sign in to comment.