보안시스템에서 중요한 두 가지 개념
code 라는 부분이 생성localstorage에 access token 저장
가입 여부에 따라 회원가입 or 메인 페이지로 redirect
처음 access token을 localstorage에 저장하는 경우: setItem이 잘 작동되지 않는 문제 발생
→ window.location.reload() 로 새로고침

Firebase 프로젝트 설정
Authentication 탭 > Sign-in method 에서 Google 활성화Firebase 라이브러리 설치
npm install firebase
Firebase 초기화
// src/firebase.js
import firebase from 'firebase/app';
import 'firebase/auth';
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID",
};
firebase.initializeApp(firebaseConfig);
export const auth = firebase.auth();
export const googleProvider = new firebase.auth.GoogleAuthProvider();
React 컴포넌트에서 로그인 구현
// src/App.js
import React from 'react';
import { auth, googleProvider } from './firebase';
const App = () => {
const signInWithGoogle = async () => {
try {
const result = await auth.signInWithPopup(googleProvider);
console.log(result.user);
} catch (error) {
console.error(error);
}
};
return (
<div>
<button onClick={signInWithGoogle}>Sign in with Google</button>
</div>
);
};
export default App;