Skip to content

Commit

Permalink
Merge pull request #41 from Soongsil-Developers/feature/#40
Browse files Browse the repository at this point in the history
[#40] 4-8. 로그아웃 만들기
  • Loading branch information
thejsw authored Sep 8, 2022
2 parents bd8ffa9 + 91ea55f commit ed4f617
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 36 deletions.
8 changes: 0 additions & 8 deletions front/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ import CreateEditArticle from './components/CreateEditArticle';
import Profile from './components/Profile';
import Settings from './components/Settings';

import {
RecoilRoot,
atom,
selector,
useRecoilState,
useRecoilValue,
} from 'recoil';

function App() {
return (
<RecoilRoot>
Expand Down
54 changes: 38 additions & 16 deletions front/src/components/Settings.jsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,79 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Signin from './Signin';

import { useRecoilState } from 'recoil';
import { useState } from 'react';
import { useEffect } from 'react';
import { LoginState } from '../atoms/Login';
import { postUsersLogin } from '../remotes';

const Settings = () => {
const [isLoggedIn, setIsLoggedIn] = useRecoilState(LoginState);

const Logout = () => {
localStorage.removeItem('token');
// LoginState(false);
if (isLoggedIn) {
setIsLoggedIn(false);
}
document.location.href = '/';
};

return (
<div>
<div class="settings-page">
<div class="container page">
<div class="row">
<div class="col-md-6 offset-md-3 col-xs-12">
<h1 class="text-xs-center">Your Settings</h1>
<div className="settings-page">
<div className="container page">
<div className="row">
<div className="col-md-6 offset-md-3 col-xs-12">
<h1 className="text-xs-center">Your Settings</h1>

<form>
<fieldset>
<fieldset class="form-group">
<fieldset className="form-group">
<input
class="form-control"
className="form-control"
type="text"
placeholder="URL of profile picture"
/>
</fieldset>
<fieldset class="form-group">
<fieldset className="form-group">
<input
class="form-control form-control-lg"
className="form-control form-control-lg"
type="text"
placeholder="Your Name"
/>
</fieldset>
<fieldset class="form-group">
<fieldset className="form-group">
<textarea
class="form-control form-control-lg"
className="form-control form-control-lg"
rows="8"
placeholder="Short bio about you"
></textarea>
</fieldset>
<fieldset class="form-group">
<fieldset className="form-group">
<input
class="form-control form-control-lg"
className="form-control form-control-lg"
type="text"
placeholder="Email"
/>
</fieldset>
<fieldset class="form-group">
<fieldset className="form-group">
<input
class="form-control form-control-lg"
className="form-control form-control-lg"
type="password"
placeholder="Password"
/>
</fieldset>
<button class="btn btn-lg btn-primary pull-xs-right">
<button className="btn btn-lg btn-primary pull-xs-right">
Update Settings
</button>
</fieldset>
</form>
<hr />
<button className="btn btn-outline-danger" onClick={Logout}>
Or click here to logout.
</button>
</div>
</div>
</div>
Expand Down
12 changes: 4 additions & 8 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 @@ -63,11 +61,9 @@ const Signin = () => {
</fieldset>

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

Sign In
</button>
</form>
Expand Down
12 changes: 8 additions & 4 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 @@ -67,10 +68,13 @@ const conduitAxios = axios.create({

// ㅡㅡㅡㅡㅡ User ㅡㅡㅡㅡㅡ
/**
* @param {{ email: string; password: string;}} user
* @returns {Promise<{ user: User }>}
* @param {{email: string; password: string;}} user
* @returns {Promise<{ data: { user: User }}>}
*/
const postUsersLogin = (user) => conduitAxios.post(`/users/login`);
const postUsersLogin = (user) =>
conduitAxios.post(`/users/login`, {
data: { email: user.email, password: user.password },
});

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

0 comments on commit ed4f617

Please sign in to comment.