일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- https://lo-victoria.com/introduction-to-redux-toolkit-for-beginners
- 헷갈린다~
- @redux-toolkit
- https://dasima.xyz/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8-%EC%A0%9C%EA%B3%B1-math-pow-%EA%B3%84%EC%82%B0/
- toString#String
- 자바스크립트
- react
- UX
- 노드교과서
- variable#function
- CSS
- 자바스크립트#JS#var#let#const#undefined#null
- dom
- 자바스크립트#JS#slice#splice
- Beesbeesbees
- ㄷㅌ
- redux상태유지
- User Flow
- js
- cmarket
- 내장고차함수
- children vs childrenNodes
- 자바스크립트#조건문#문자열
- removeCookie
- UI
- slice/splice/split
- for~in/for~of
- https://www.daleseo.com/js-array-slice-splice/
- https://developer-talk.tistory.com/299
- JS#3일차달리자#초반인데#시간금방~
- Today
- Total
Daily Front_Minhhk
[firebase] 회원가입 (createUserWithEmailAndPassword, updateProfile ) 본문
[firebase] 회원가입 (createUserWithEmailAndPassword, updateProfile )
Minhhk 2023. 5. 7. 21:151. 파이어베이스 회원가입 (이메일 & 패스워드)
공식문서 예제는 이렇다.
getAuth 는 firebase.js 에서 export 한 값을 사용 했다.
signInWithEmailAndPassword 과 updateProfile 을 사용하여 우선 가입의 사이클을 완성 해 보았다.
비동기로
import { getAuth, signInWithEmailAndPassword } from "firebase/auth";
const auth = getAuth();
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
});
import { getAuth, updateProfile } from "firebase/auth";
const auth = getAuth();
updateProfile(auth.currentUser, {
displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(() => {
// Profile updated!
// ...
}).catch((error) => {
// An error occurred
// ...
});
by
아래 파이어베이스 공식문서를 참고하자!
Firebase에서 사용자 관리하기
의견 보내기 Firebase에서 사용자 관리하기 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 사용자 생성하기 Firebase 프로젝트에서 신규 사용자를 생성할 때는 c
firebase.google.com
2. 사용자 랜덤 포토 생성 > 그라바타와 md5 이용
Gravatar - 전세계적으로 인정된 아바타
Image Requests ← Back Base Request Gravatar images may be requested just like a normal image, using an IMG tag. To get an image specific to a user, you must first calculate their email hash. The most basic image request URL looks like this: https://www.g
ko.gravatar.com
그라바타 사용은 우선
https://www.gravatar.com/avatar/HASH값?d=???
이러한 형태로 사용 해라고 명시 되어 있다.
[If you'd prefer to use your own default image (perhaps your logo, a funny face, whatever), then you can easily do so by supplying the URL to an image in the d= or default= parameter.
The URL should be URL-encoded to ensure that it carries across correctly, for example
]
md5 === 128비트 해시 함수
가입 할 때 유니크한 값을 얻기 위하여 사용!
npm i md5
마지막으로 완성한 코드이다.
폼 작성 후 가입버튼 누를 때, 비동기로 형태로, 전체적 try ~ catch 아래에 두어 한번에 작성 하였다.
const onSubmit = async (data) => {
// data 에 입력 값 [이메일,네임,비번,비번확인] 들어 있음
// console.log(data);
try {
// 파이어베이스 가입 POST
setLoading(true);
const register = await createUserWithEmailAndPassword(
appAuth,
data.email,
data.password
);
console.log(register);
// 파이어베이스 유저정보 업데이트 POST {displayName : 가입 이름, photoURL : md5(유니크한 값,email로 구분),그라바타 이용한 랜덤 이미지 포토}
const upProfile = await updateProfile(appAuth.currentUser, {
displayName: data.name,
photoURL: `https://www.gravatar.com/avatar/${md5(
register.user.email
)}?d=monsterid`,
});
console.log(upProfile);
// 파이어베이스 데이터베이스 저장
setLoading(false);
} catch (error) {
setErrorForm(error.message);
// console.log(error);
setLoading(false);
setTimeout(() => {
setErrorForm("");
}, 3000);
}
};
>>
email, name, photoURL 등등 값이 들어온 걸 확인 할 수 있다.
'Project > ChatProject' 카테고리의 다른 글
[firebase] storage 설정 (+ 파일 업로드, 다운로드) (0) | 2023.05.10 |
---|---|
[firebase] 이메일,비밀번호 로그인 & 구글로그인 & 로그아웃 (0) | 2023.05.08 |
[firebase] 실시간 데이터베이스 쓰기 (0) | 2023.05.08 |
react-hook-form / 가입폼, 유효성 검사 (라이브러리) (0) | 2023.05.07 |