Foundation
yarn add firebase
or
npm install firebase
packge.json
에 firebase가 입력되어 있으면 성공적으로 설치가 된 것이다!👏
Firebase
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: ""
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
(API key 와 id 등 정보는 개인정보로 인해서 지웠다🔒 값들은 firebase에서 프로젝트를 만들면 자동으로 생성된다.)
여기까지 작성하면 기본적인 초기 셋팅은 완성이다.
하지만, v8과 v9에 따라 작성하는 방법이 다르기 때문에 공식문서를 꼭 확인해야한다.
firebase 공식문서
버전 9 호환 코드는 버전 8 코드와 동일하지만 가져오기가 변경되었다.
import firebase from "firebase/compat/app";
import "firebase/compat/auth";
const auth = firebase.auth();
auth.onAuthStateChanged(user => {
// Check for user status
});
이후: 버전 9 모듈식
import { getAuth, onAuthStateChanged } from "firebase/auth";
const auth = getAuth(firebaseApp);
onAuthStateChanged(auth, user => {
// Check for user status
});
https://firebase.google.com/docs/reference/js/v8/firebase.auth?hl=ko&authuser=0
출처: https://firebase.google.com/docs/web/modular-upgrade?hl=ko&authuser=0