Firebase 회원가입

준영·2023년 2월 20일
0

Firebase를 써보자..

목록 보기
2/8
post-thumbnail

설정

firebase.config.ts

📗 config 설정은 다음을 참고

signup.container.tsx import

import {
  firebaseAuth,
  createUserWithEmailAndPassword,
} from "../../../firebase.config";

signup.container.tsx func

check func

// check func
const goToSignUp = () => {
  const reg =
        /^[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/i;

  // e-mail check
  if (reg.test(id) == false || id == "") {
    alert("Plz check your e-mail");
    return;
  }
  // pass check
  if (pass.length < 6 || pass == "") {
    alert("Password must be at least 6 digits");
    return;
  }
  // confirm pass check
  if (pass !== rePass || rePass == "") {
    alert("Must be the same as the password");
    return;
  }

  console.log("All check OK!");
  signUp(id, pass);
};

signUp func

// signUp func
const signUp = async (id: string, pass: string) => {
  try {
    const data = await createUserWithEmailAndPassword(firebaseAuth, id, pass);
    alert("Success signUp!");
    console.log(data);
    router.push("/login");
  } catch (err) {
    if (err.code == "auth/email-already-in-use") {
      alert("E-mail already in use!");
    } else if (err.code == "auth/invalid-email") {
      alert("Invalid e-mail!");
    } else if (err.code == "auth/weak-password") {
      alert("Weak password!");
    }
  }
};


파이어베이스 Authentication -> Users를 보면, 가입한 이메일로 회원가입이 되어있는 모습을 볼 수 있다.

profile
개인 이력, 포폴 관리 및 기술 블로그 사이트 👉 https://aimzero-web.vercel.app/

0개의 댓글