Skip to content

Commit

Permalink
Merge pull request #3 from noSPkeepgoing/ChoiSunPa
Browse files Browse the repository at this point in the history
[feat] 회원가입 성공 시 새로운 유저 database 생성
  • Loading branch information
noSPkeepgoing authored Sep 14, 2023
2 parents 7912640 + 9135730 commit d71d3d7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
12 changes: 5 additions & 7 deletions src/components/SignUp/SignUpNext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ export function SignUpNext({
setErrorMessage('개인정보 약관에 동의해주세요.');
return;
}
await createUserAuth();
await createNewUser();
};

// user auth 생성
const createUserAuth = async () => {
const { email, password, nickname } = user;
// user auth 생성 후 정보 추가
const createNewUser = async () => {
try {
await createUser(email, password);
alert(`${nickname}님 반갑습니다!`);
console.log(user);
await createUser(user);
alert(`${user.nickname}님 반갑습니다!`);
} catch (error: any) {
handleError(error);
}
Expand Down
1 change: 0 additions & 1 deletion src/components/SignUp/SignUpPrev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export function SignUpPrev({
value={nickname}
placeholder="* 닉네임"
readOnly
required
/>
<button type="button" onClick={handleClickNicknameButton}>
추천받기!
Expand Down
8 changes: 5 additions & 3 deletions src/data/getUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { collection, getDocs } from 'firebase/firestore';
const querySnapshot = await getDocs(collection(db, 'User'));
const getDocumentsAsObjects = (querySnapshot) => {
const documents = [];

querySnapshot.forEach((doc) => {
const { username, nickname, email, image } = doc.data();
documents.push({
id: doc.id,
name: doc.data().name,
photo: doc.data().photo,
username,
nickname,
email,
image,
});
});
return documents;
Expand Down
24 changes: 21 additions & 3 deletions src/data/user.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import { getAuth, createUserWithEmailAndPassword } from 'firebase/auth';
import { getStorage, ref, getDownloadURL, uploadBytes } from 'firebase/storage';
import { app } from './firebase';
import { doc, setDoc } from 'firebase/firestore';
import { app, db } from './firebase';
import { adjective, emoji, noun } from './nickname';

const auth = getAuth(app);

// 이메일로 회원가입
export const createUser = async (email, password) => {
await createUserWithEmailAndPassword(auth, email, password);
export const createUser = async (user) => {
const { email, password } = user;
await createUserWithEmailAndPassword(auth, email, password).then(
(userCredential) => {
const uid = userCredential.user.uid;
createUserData(user, uid);
},
);
};

// user 데이터 생성
export const createUserData = async (user, id) => {
const { username, email, nickname, image } = user;
setDoc(doc(db, 'User', id), {
username,
email,
nickname,
image,
});
};

// 유저 프로필 사진
Expand Down

0 comments on commit d71d3d7

Please sign in to comment.