Skip to content

Commit

Permalink
[feat] boostcampwm-2022#85 유저 정보 전역 저장
Browse files Browse the repository at this point in the history
- 로그인이 되어있는 경우, 메인페이지에서 유저 정보 전역으로 저장
  • Loading branch information
ktmihs committed Nov 28, 2022
1 parent 2f2de80 commit 055bce7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions frontend/src/page/Main/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import axios from 'axios';
import { useEffect, useState } from 'react';
import { useRecoilState } from 'recoil';
import Background from '../../component/Background';
import MainContent from '../../component/MainContent';
import { userState } from '../../store/atom/user';

const Main = () => {
const [hasToken, setHasToken] = useState(false);
const [user, setUser] = useRecoilState(userState);

useEffect(() => {
const checkAuth = async () => {
const data = await axios.get('/api/user/auth');
data.status === 200 ? setHasToken(true) : setHasToken(false);
const response = await axios.get('/api/user/auth');
response.status === 200 ? setHasToken(true) : setHasToken(false);

setUser({
nickname: response.data.nickname,
hair: response.data.characterName,
});
};

checkAuth();
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/store/atom/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { atom } from 'recoil';

export interface userProps {
nickname: string;
hair: number;
hair: string;
}

export const userState = atom<userProps>({
key: 'userState',
default: {
nickname: '',
hair: -1,
hair: '',
},
});

0 comments on commit 055bce7

Please sign in to comment.