Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Match-Box-Team/FrontEnd into fea…
Browse files Browse the repository at this point in the history
…tue/6-채팅방페이지
  • Loading branch information
Joo-hyun-Kang committed Apr 27, 2023
2 parents ef53733 + 7702b47 commit 052fa7f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"react-switch": "^7.0.0",
"recoil": "^0.7.7",
"socket.io-client": "^4.6.1",
"recoil-persist": "^4.2.0",
"styled-components": "^5.3.9",
"styled-normalize": "^8.0.7",
"typescript": "^4.9.5",
Expand Down
23 changes: 5 additions & 18 deletions src/components/pages/login/auth-page/Auth.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import axios, { AxiosResponse } from 'axios';
import axios from 'axios';
import { useNavigate } from 'react-router-dom';
import { useCookies } from 'react-cookie';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { useSetRecoilState } from 'recoil';
import { userState } from '../../../../recoil/locals/login/atoms/atom';
import Layout from '../../../commons/layout/Layout';
import Header from '../../../commons/header/Header';
import { getImageUrl } from '../../../../api/ProfileImge';

const GetImageUrl = async (userId: string): Promise<string> => {
// recoil 유저 토큰
const userInfo = useRecoilValue(userState);
const response: AxiosResponse<Blob> = await axios.get(
`http://localhost:3000/account/image?userId=${userId}`,
{
responseType: 'blob',
headers: { Authorization: `Bearer ${userInfo.token}` },
},
);
const imageUrl: string = URL.createObjectURL(response.data);
return imageUrl;
};

export default function Auth() {
// 페이지 이동
const navigate = useNavigate();
Expand All @@ -32,8 +18,8 @@ export default function Auth() {
const [inputValue, setInputValue] = useState('');
// recoil 유저 토큰 저장
const setUserState = useSetRecoilState(userState);
// 쿠키에서 userId 받기
const [cookies] = useCookies(['token']);
// 쿠키
const [cookies, setCookie, removeCookie] = useCookies(['token']);

// 입력 변화 핸들러
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -66,6 +52,7 @@ export default function Auth() {
imageUrl: userImage,
};
console.log(storeUser);
removeCookie('token');
setUserState(storeUser);
navigate(`/chat/channel`);
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions src/recoil/locals/login/atoms/atom.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { recoilPersist } from 'recoil-persist';
import { atom } from 'recoil';

const { persistAtom } = recoilPersist();

const user = {
token: '',
userId: '',
Expand All @@ -10,4 +13,5 @@ const user = {
export const userState = atom({
key: 'userState',
default: user,
effects_UNSTABLE: [persistAtom],
});

0 comments on commit 052fa7f

Please sign in to comment.