-
Notifications
You must be signed in to change notification settings - Fork 15
Added Toast for Login and signup #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: workspace
Are you sure you want to change the base?
Changes from 5 commits
251725a
7cfd8eb
d70263c
ce18863
32b6ce5
82e0f94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,31 +7,51 @@ import { | |
| import { auth } from "../firebase"; | ||
|
|
||
| import { useEffect } from "react"; | ||
|
|
||
| import { useNavigate } from "react-router-dom"; | ||
| import FormContainer from "../components/Form/FormContainer"; | ||
|
|
||
| import { Button, VStack, HStack, useColorMode } from "@chakra-ui/react"; | ||
| import { ToastContainer, toast } from 'react-toastify'; | ||
| import 'react-toastify/dist/ReactToastify.css'; | ||
|
|
||
| import FormContainer from "../components/Form/FormContainer"; | ||
| import { Button, VStack, HStack, useColorMode } from "@chakra-ui/react"; | ||
| import YupValidation, { initialValues } from "../components/Form/YupSignIn"; | ||
| import TextField from "../components/Form/TextField"; | ||
| import { Formik, Form } from "formik"; | ||
|
|
||
| import { IconContext } from "react-icons"; | ||
| import { FiLogIn } from "react-icons/fi"; | ||
|
|
||
| const getAuthErrorMessage = (error) => { | ||
| switch (error.code) { | ||
| case 'auth/user-not-found': | ||
| case 'auth/wrong-password': | ||
| case 'auth/invalid-credential': | ||
| return 'Invalid email or password. Please try again.'; | ||
| case 'auth/invalid-email': | ||
| return 'Please enter a valid email address.'; | ||
| case 'auth/too-many-requests': | ||
| return 'Too many attempts. Please try again later or reset your password.'; | ||
| case 'auth/popup-closed-by-user': | ||
| case 'auth/cancelled-popup-request': | ||
| return 'The sign-in process was cancelled.'; | ||
| case 'auth/popup-blocked': | ||
| return 'Pop-up blocked. Please allow pop-ups for this site to sign in.'; | ||
| default: | ||
| return 'An unexpected error occurred. Please try again.'; | ||
| } | ||
| }; | ||
|
|
||
| export default function Signin() { | ||
| const Navigate = useNavigate(); | ||
| const { colorMode } = useColorMode(); | ||
|
|
||
| useEffect(() => { | ||
| onAuthStateChanged(auth, (user) => { | ||
| const unsubscribe = onAuthStateChanged(auth, (user) => { | ||
| if (user) { | ||
| Navigate("/main"); | ||
| } | ||
| }); | ||
| // eslint-disable-next-line | ||
| }, [auth]); | ||
| return () => unsubscribe(); | ||
| }, [Navigate]); | ||
|
|
||
| const NavToSignUp = () => { | ||
| Navigate("/signup"); | ||
|
|
@@ -40,28 +60,33 @@ export default function Signin() { | |
| const SignInWithGoogle = () => { | ||
| const provider = new GoogleAuthProvider(); | ||
| signInWithPopup(auth, provider) | ||
| .then((cred) => { | ||
| console.log("Log in successfully"); | ||
| .then(() => { | ||
| toast.success("Successfully logged in!"); | ||
| }) | ||
| .catch((err) => { | ||
| console.log(err); | ||
| const message = getAuthErrorMessage(err); | ||
| toast.error(message); | ||
| console.error("Firebase Google Auth Error:", err); | ||
| }); | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| const SignInWithEmailPassword = (values, actions) => { | ||
| signInWithEmailAndPassword(auth, values.email, values.password) | ||
| .then(() => { | ||
| toast.success("Successfully logged in!"); | ||
| actions.setSubmitting(false); | ||
| console.log("Sign in Successfully"); | ||
| }) | ||
| .catch((err) => { | ||
| const message = getAuthErrorMessage(err); | ||
| toast.error(message); | ||
| actions.setSubmitting(false); | ||
| console.error("Something went wrong", err); | ||
| console.error("Firebase Email Auth Error:", err); | ||
| }); | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| return ( | ||
| <FormContainer Icon={LoginIcon} title="Sign in for an account!"> | ||
| <FormContainer Icon={LoginIcon} title="Sign in to your account!"> | ||
| <ToastContainer position="top-right" autoClose={5000} hideProgressBar={false} /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Move ToastContainer to app root level. Rendering Recommended approach:
Example in import { ToastContainer } from 'react-toastify';
function App() {
return (
<>
<ToastContainer
position="top-right"
autoClose={5000}
hideProgressBar={false}
/>
{/* Your routes and components */}
</>
);
}Then you can call 🤖 Prompt for AI Agents |
||
| <Formik | ||
| initialValues={initialValues} | ||
| validationSchema={YupValidation} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.