// Signup.jsx
import { createUserWithEmailAndPassword, updateProfile } from 'firebase/auth';
const defaultPhotoUrl = 'μ΄λ―Έμ§ url';
try {
const userCredential = await createUserWithEmailAndPassword(
auth,
inputs.email,
inputs.password
);
await updateProfile(userCredential.user, {
displayName: inputs.nickname,
photoURL: defaultPhotoUrl
});
toast.success('νμκ°μ
μ΄ λμμ΅λλ€!');
navigate('/login');
} catch (error) {
toast.error(errorMsg(error.code));
}
// νμκ°μ
ν μΈνμ°½ λΉμ°κΈ°
setInputs({
email: '',
nickname: '',
password: ''
});
};
// Sign.jsx
import { signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider } from 'firebase/auth';
const loginGoogle = async (e) => {
e.preventDefault();
const provider = new GoogleAuthProvider();
try {
const userCredential = await signInWithPopup(auth, provider);
toast.success('λ‘κ·ΈμΈ λμμ΅λλ€!');
localStorage.setItem('accessToken', userCredential.user.accessToken);
navigate('/');
dispatch(login(userCredential.user));
} catch (error) {
console.log(error.message);
toast.error('λ‘κ·ΈμΈμ μ€ν¨νμ΅λλ€. λ€μ μλν΄μ£ΌμΈμ.');
}
};
1. yarn add react-toastify μ€μΉ
yarn add react-toastify
2. react-toastify μ¬μ©λ²
// index.js
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
// νμν νμΌμμ λͺ¨λ λΆλ¬μ€κΈ°
// Signup.jsx
import { toast } from "react-toastify"
// toastify μλ μ€ν ν¨μ λ§λ€κΈ°
export default function Signup () {
const checkInputs = () => {
if (
inputs.email.trim().length === 0 ||
inputs.password.trim().length === 0 ||
inputs.nickname.trim().length === 0
) {
toast.error('μ 보λ₯Ό λͺ¨λ μ
λ ₯ν΄μ£ΌμΈμ');
resetInputs();
return;
}
if (inputs.nickname.length < 2) {
toast.error('λλ€μμ 2μ μ΄μμ΄μ΄μΌ ν©λλ€');
resetInputs();
return;
}
return true;
};
3. λ€μν μλ μ¬μ©νκΈ°
// μ±κ³΅ μλ (μ΄λ‘μ μ°½)
const success = () => toast.success("Success!");
// μ€ν¨ μλ (λΉ¨κ°μ μ°½)
const error = () => toast.error("Error!");
// κ²½κ³ μλ (λ
Έλμ μ°½)
const warning = () => toast.warning("Warning!");
// μ 보 μλ
const info = () => toast.info("Info...");
https://fkhadra.github.io/react-toastify/introduction/
μ μ¬μ΄νΈμμ λ€μν μ΅μ
λ€λ‘ λ°λͺ¨κ° κ°λ₯νλ μ°Έκ³ !
// μ΄μ μ½λ
const moveLoginPage = (e) => {
e.preventDefault();
navigate('/login');
};
<span onClick={moveRegisterPage}>κ°μ
νλ¬κ°κΈ°</span>
span {
cursor: pointer;
font-weight: bold;
color: #f1cc13;
margin-top: 10px;
}
// λ°κΎΌ μ½λ
<Stlink to="/register">κ°μ
νλ¬κ°κΈ°</Stlink>
const Stlink = styled(Link)`
cursor: pointer;
font-weight: bold;
color: #f1cc13;
margin-top: 10px;
`;
Link
<a>
νκ·Έλ₯Ό λ§λ€μ΄μ€useNavigate
<a>
νκ·Έλ₯Ό λ§λ€μ§ μκ³ , μ½λλ‘ νμ΄μ§λ₯Ό μ΄λν¨<span>
νκ·Έλ κ°λ°μ λκ΅¬λ‘ μ΄λ νμ΄μ§λ‘ κ°λμ§ νμΈμ λΆκ°ν¨μ€λ μ λ§ μ€λ₯μ λͺμμ λ²μ΄λμ§ λͺ»ν΄μ λ§€μ° νλ€μλ€γ κ·ΈμΉλ§ μ€λ₯λ₯Ό ν΄κ²°ν λμ κ·Έ μΎκ°μ΄λ....! μ¬κΈ°κΉμ§ μ§νν κ²λ§μΌλ‘λ κ°κ²©μ€λ½μ§λ§ μμ§λ ꡬνν κ² λ§λ€^^ μ΄μ λ§ ν΄λ κ±°μ λ€ ν μ€ μμλλ° μκ°λ³΄λ€ μ€λ 걸리λ κ±° κ°λ€. λ΄μΌ λ§μ λ§λ¬΄λ¦¬νλ κ² λͺ©ν! μλ²½μ λ¨μμ μ½λ©νλ€κ° κ°μ νμλΆκ»μ κ°λ°μ λꡬλ₯Ό μ΄μ΄μ μμ±μ 보λ λ²λ μλ €μ£Όμκ³ μ’ λ μλ©ν±νκ² μ½λλ₯Ό μ§λ λ²μ μλ €μ£Όμ ¨λ€. μμ€λ³ μμ λ λ°°μ λ κ°λ μ νλ‘μ νΈμμ μ§μ μ μ©ν΄λ³΄λ ν 체κ°μ΄ λλ€. νμ λλΌλ κ±°μ§λ§ μ’μ λκΈ°λ₯Ό λ§μ΄ λ§λκ² λλ 건 μ°Έ ν° λ³΅μΈ κ±° κ°μ!