Skip to content

Commit

Permalink
[๐Ÿฅ : feat] ์†Œ์…œ๋กœ๊ทธ์ธ ์‹œ, ์œ ์ € ์ •๋ณด firestore์— ์ €์žฅ (#3)
Browse files Browse the repository at this point in the history
- ํ”„๋กœํ•„ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค๋ฃจ๋Š” ๊ณผ์ •์—์„œ ํšŒ์›์˜ ์ •๋ณด๋ฅผ firestore์— ์ €์žฅํ•  ํ•„์š”์„ฑ์„ ํ™•์ธ. ์ด๋ฉ”์ผ/๋น„๋ฐ€๋ฒˆํ˜ธ ํšŒ์›๊ฐ€์ž… ์‹œ ์ ์šฉ์€ ์ด์ „ ์ž‘์—…์—์„œ ์™„๋ฃŒ (75ed77b)
  • Loading branch information
sryung1225 committed Dec 15, 2023
1 parent 75ed77b commit 095fec7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/socialSignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 095fec7

Please sign in to comment.