others TIL
[Firebase] auth, firestore 초기설정
코코리니
2024. 4. 8. 00:05
반응형
firebase config 설정 후
const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_apiKey,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_uthDomain,
projectId: process.env.NEXT_PUBLIC_FIREBASE_projectId,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_storageBucket,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_messagingSenderId,
appId: process.env.NEXT_PUBLIC_FIREBASE_appId,
measurementId: process.env.NEXT_PUBLIC_FIREBASE_measurementId
};
const app = initializeApp(firebaseConfig);
Authorization / FireStore 설정을 하기 위해서
const auth = firebase.auth(app);
const fireStore = firebase.firestore(app);
예시와 같이 설정했지만 오류 발생.. auth 와 firestore 는 함수 또는 메서드로 사용할 수없다는 오류가 발생.
버전에 올라가면서 설정과 사용 방법이 변경 되었다.
// 변경된 설정 방법
const auth = getAuth(app);
const store = getFirestore(app);
// 기존 사용방법 (auth)
let res = await auth.signInWithEmailAndPassword(email, password);
//변경된 사용방법(auth)
let res = await signInWithEmailAndPassword(auth, email, password);
// 기존 사용방법 (fireStore)
let res = await fireStore.collection("이름").doc("이름").get();
//변경된 사용방법(fireStore)
const docRef = doc(store, "userInfo", uid);
let res = await getDoc(docRef);
조금 더 명확하게 세분화 된듯한 느낌이 든다.
끝.
반응형