From 095fec7874343179d9d14b162bc3d75bb5b15453 Mon Sep 17 00:00:00 2001 From: sryung Date: Fri, 15 Dec 2023 16:48:18 +0900 Subject: [PATCH] =?UTF-8?q?[=F0=9F=A5=81=20:=20feat]=20=EC=86=8C=EC=85=9C?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=8B=9C,=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=20firestore=EC=97=90=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=20(#3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 프로필 이미지를 다루는 과정에서 회원의 정보를 firestore에 저장할 필요성을 확인. 이메일/비밀번호 회원가입 시 적용은 이전 작업에서 완료 (75ed77b) --- src/components/socialSignIn.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/socialSignIn.tsx b/src/components/socialSignIn.tsx index afbfe1b..e3ca06c 100644 --- a/src/components/socialSignIn.tsx +++ b/src/components/socialSignIn.tsx @@ -2,7 +2,8 @@ import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { FirebaseError } from 'firebase/app'; import { AuthProvider, signInWithPopup } from 'firebase/auth'; -import { auth } from '../firebase.ts'; +import { doc, setDoc } from 'firebase/firestore'; +import { auth, db } from '../firebase.ts'; import * as S from '../styles/auth.ts'; interface ISocialButton { @@ -22,7 +23,13 @@ export default function SocialSignIn({ provider, icon, text }: ISocialButton) { const onClick = async () => { setFirebaseError(''); try { - await signInWithPopup(auth, provider); + const credentials = await signInWithPopup(auth, provider); + const userRef = doc(db, 'users', credentials.user.uid); + await setDoc(userRef, { + userName: credentials.user.displayName || 'Anonymous', + userId: credentials.user.uid, + userAvatar: credentials.user.photoURL || null, + }); navigate('/'); } catch (error) { if (error instanceof FirebaseError) {