Commit 8c1c74f5 authored by Spark's avatar Spark
Browse files

cookies component

parent 7a11adee
import React from 'react'
import { Swal } from 'sweetalert2';
export function checkCookies() {
const acctoken_cookies = document.cookie.split('=')[1];
return acctoken_cookies;
}
export function deleteCookie (name) {
document.cookie = name + '=; expires=Thu, 01 Jan 1999 00:00:10 GMT;';
Swal.fire({
title: '로그아웃 성공!',
text: '🙏 안녕히 가세요 🙏',
icon: 'warning',
customClass: 'swal-wide',
confirmButtonText: '확인',
}).then((res) => {
if (res.isConfirmed) {
window.location.replace('/')
}
else {
window.location.replace('/')
}
})
}
\ No newline at end of file
...@@ -6,6 +6,8 @@ import UserInfo from './UserInfo'; ...@@ -6,6 +6,8 @@ import UserInfo from './UserInfo';
import { kakaoLogout } from '../utils/Oauth'; import { kakaoLogout } from '../utils/Oauth';
import axios from 'axios'; import axios from 'axios';
import { Swal } from 'sweetalert2'; import { Swal } from 'sweetalert2';
import { deleteCookie } from '../utils/Cookies';
import { checkCookies } from './../utils/Cookies';
function MainLayer() { function MainLayer() {
...@@ -34,8 +36,6 @@ function MainLayer() { ...@@ -34,8 +36,6 @@ function MainLayer() {
color: 'white' color: 'white'
} }
const acctoken_cookies = document.cookie.split('=')[1];
// console.log(acctoken_cookies)
const logined = localStorage.getItem('nickname') const logined = localStorage.getItem('nickname')
const [airUsing, setAirUsing] = useState(false) const [airUsing, setAirUsing] = useState(false)
...@@ -55,23 +55,7 @@ function MainLayer() { ...@@ -55,23 +55,7 @@ function MainLayer() {
} }
}); });
var deleteCookie = function (name) {
document.cookie = name + '=; expires=Thu, 01 Jan 1999 00:00:10 GMT;';
Swal.fire({
title: '로그아웃 성공!',
text: '🙏 안녕히 가세요 🙏',
icon: 'warning',
customClass: 'swal-wide',
confirmButtonText: '확인',
}).then((res) => {
if (res.isConfirmed) {
window.location.replace('/')
}
else {
window.location.replace('/')
}
})
}
return ( return (
...@@ -86,7 +70,7 @@ function MainLayer() { ...@@ -86,7 +70,7 @@ function MainLayer() {
<UserInfo /> <UserInfo />
</Row> </Row>
{acctoken_cookies && {checkCookies() &&
<Form <Form
key='checkbox' className="d-flex justify-content-center w-100" style={{ flexDirection: 'row-reverse' }}> key='checkbox' className="d-flex justify-content-center w-100" style={{ flexDirection: 'row-reverse' }}>
<Form.Check <Form.Check
...@@ -101,7 +85,7 @@ function MainLayer() { ...@@ -101,7 +85,7 @@ function MainLayer() {
<Row className='d-flex justify-content-center align-items-center my-2 mx-auto w-100'> <Row className='d-flex justify-content-center align-items-center my-2 mx-auto w-100'>
<ButtonGroup vertical className='m-auto' style={{ width: '100%', flexDirection: 'column' }}> <ButtonGroup vertical className='m-auto' style={{ width: '100%', flexDirection: 'column' }}>
{acctoken_cookies ? {checkCookies() ?
//true //true
<Button variant='light' style={btnstyled} onClick={kakaoLogout || deleteCookie('acs_token')}> <Button variant='light' style={btnstyled} onClick={kakaoLogout || deleteCookie('acs_token')}>
로그아웃 로그아웃
...@@ -114,7 +98,7 @@ function MainLayer() { ...@@ -114,7 +98,7 @@ function MainLayer() {
</Link> </Link>
</Button> </Button>
} }
{!acctoken_cookies && {!checkCookies() &&
<Button variant='light' style={btnstyled}> <Button variant='light' style={btnstyled}>
<Link to='/signup' id='btnlink'> <Link to='/signup' id='btnlink'>
회원가입 회원가입
......
...@@ -47,20 +47,6 @@ function SignupComp() { ...@@ -47,20 +47,6 @@ function SignupComp() {
} }
console.log('???', formValues) console.log('???', formValues)
// function CheckUserExist() {
// const signUser = localStorage.getItem('signup_username')
// const signEmail = localStorage.getItem('signup_email_Address').split('@')[1]
// if (signEmail && signUser) {
// setAlertShow(true)
// setUserExist(!userExist)
// }
// else
// if (!signEmail) {
// setAlertShow(false)
// }
// }
async function handleSubmit(event) { async function handleSubmit(event) {
event.preventDefault(); event.preventDefault();
await axios.post("/api/signup", formValues) await axios.post("/api/signup", formValues)
......
...@@ -2,6 +2,7 @@ import React, { useState } from 'react' ...@@ -2,6 +2,7 @@ import React, { useState } from 'react'
import { Row, Card, Button, Col, Modal } from 'react-bootstrap'; import { Row, Card, Button, Col, Modal } from 'react-bootstrap';
import '../App.css' import '../App.css'
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { checkCookies } from './../utils/Cookies';
function UserInfo() { function UserInfo() {
...@@ -44,7 +45,7 @@ function UserInfo() { ...@@ -44,7 +45,7 @@ function UserInfo() {
<Card style={cardstyled} id='localName'> <Card style={cardstyled} id='localName'>
<Card.Title> <Card.Title>
<strong> <strong>
{nickname ? {checkCookies() ?
<h2> <h2>
{`${nickname}`} {`${nickname}`}
</h2> </h2>
...@@ -76,7 +77,7 @@ function UserInfo() { ...@@ -76,7 +77,7 @@ function UserInfo() {
</p> </p>
} }
</Card.Subtitle> </Card.Subtitle>
{nickname && {checkCookies() &&
<Button variant='light' className='m-auto d-flex' style={btnstyled2}> <Button variant='light' className='m-auto d-flex' style={btnstyled2}>
<Link to='/edit' className='w-100' style={{ textDecoration: 'none', color: 'rgb(110, 189, 142)' }}> <Link to='/edit' className='w-100' style={{ textDecoration: 'none', color: 'rgb(110, 189, 142)' }}>
변경 변경
...@@ -84,7 +85,7 @@ function UserInfo() { ...@@ -84,7 +85,7 @@ function UserInfo() {
</Button> </Button>
} }
</Row> </Row>
{nickname && {checkCookies() &&
<p className='w-100 justify-content-center m-auto'> <p className='w-100 justify-content-center m-auto'>
<hr /> <hr />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment