Skip to content

Commit

Permalink
[Feat]구글 로그인 구현
Browse files Browse the repository at this point in the history
로그인 시 전역변수에 로그인상태 저장 및 헤더 변경
토큰을 로컬 스토리지에 저장
 Isseus #15
  • Loading branch information
김병현 authored and 김병현 committed Sep 12, 2023
1 parent 1ce4d98 commit cacec84
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 14 additions & 0 deletions client/src/components/Logins/GoogleSignin.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import React from 'react';
import { GoogleOAuthProvider, GoogleLogin, useGoogleOneTapLogin } from '@react-oauth/google';
import { useDispatch } from 'react-redux';
import { setLoginState } from '../../reducer/member/loginSlice';

const GoogleSignInComponent: React.FC = () => {

const dispatch = useDispatch(); // Redux의 dispatch 함수를 사용하기 위해 가져옵니다.

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleSuccess = (credentialResponse: any) => {
console.log(credentialResponse);

const token = credentialResponse.token; // 실제 응답에서 토큰의 경로가 어떤지 확인하고 수정해야 합니다.
localStorage.setItem('authToken', token); // 토큰을 localStorage에 저장

// 로그인 성공 시 전역 상태를 업데이트합니다.
dispatch(setLoginState({
memberId: credentialResponse.memberId, // memberId는 예시입니다. 실제 값에 맞게 수정해야 합니다.
isLoggedIn: 1,
}));
};

const handleError = () => {
Expand Down
3 changes: 0 additions & 3 deletions client/src/page/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ import Holdings from "../components/watchlist/Holdings"; // Assuming you have a
import CompareChartSection from "../components/CompareChartSection/Index";
import StockOrderSection from "../components/StockOrderSection/Index";
import Welcome from "../components/Signups/Welcome";

import ProfileModal from "../components/Profile/profileModal";

import { StateProps } from "../models/stateProps";

import { TabContainerPage } from "./TabPages/TabContainerPage";

const MainPage = () => {
Expand Down
6 changes: 3 additions & 3 deletions client/src/reducer/member/loginSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ const loginSlice = createSlice({
name: 'login',
initialState: {
memberId: null,
isLoggedOut: 1
isLoggedIn: 1
},
reducers: {
setLoginState: (state, action) => {
state.memberId = action.payload;
state.isLoggedOut = 0;
state.isLoggedIn = 1;
},
setLogoutState: (state) => {
state.memberId = null;
state.isLoggedOut = 1;
state.isLoggedIn = 0;
},
updateMemberId: (state, action) => {
state.memberId = action.payload;
Expand Down

0 comments on commit cacec84

Please sign in to comment.