Skip to content

Commit

Permalink
sign-in edge cases fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Us-sync committed Dec 14, 2023
1 parent b5c49e7 commit d6e95ec
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .firebase/hosting.ZGlzdA.cache
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ arrow.svg,1687776548692,321f8cdb8961e7e78634152b4ed5430de6e107a76ae16c2b71df573b
Banner-Alumni.jpg,1686212548651,b78891b0391eeb97ceeba91f512d9a447103ba5066e9be5cef68bec9765bac65
google.svg,1686144473255,77de1ffebe1809350cf97a387b526c86da8499ed438035bd745cc8b23a2f10eb
homebanner.png,1686209137776,acd8bfee72fde2bb53175ba985ac377497acd4287a1cc97d333e59bdd66d56f9
index.html,1689448648380,8ea4b810ab192e4ea164e1dc0969faea4e19ace288702a7c934a9764fdab9c65
job_01.png,1685608872139,3e4a183a0e930faae381735f35cd3cae9632e342b8145b08362b9cdb5ca96216
signin.svg,1686127288433,f60118db2a3203e28dc8285cf5d2dafbc799618ee6b2a4d0d3a63f36ba584c8e
vite.svg,1680593882164,59ec4b6085a0cb1bf712a5e48dd5f35b08e34830d49c2026c18241be04e05d5a
assets/index-33d6b8f6.js,1689448648380,6bbeafe55bf300ddf7bff8d24c569d9df5e43b36023b835a9b58fd8b7a40c7f9
assets/index-7245ca49.css,1689448648380,5f38b69f5bf2b3fa5d7290ed6885b7b56c40a0815451f4aa65fd78f81d93f61c
index.html,1694890221333,6a1991e7af5c4e09413579e31dec3b0b9dee84279f32c11e23473443f03b11e0
assets/index-7245ca49.css,1694890221333,5f38b69f5bf2b3fa5d7290ed6885b7b56c40a0815451f4aa65fd78f81d93f61c
assets/index-364b5e08.js,1694890221333,386b261e8d2a0d381c469b14ec435d04234bbeb8a8df5be5cebc22828fc766e6
4 changes: 3 additions & 1 deletion src/components/OnBoardingForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const OnBoardingForm = () => {
linkedin: "",
bio: "",
currentCompany: "",
isVerified: false,
});
const [image, setImage] = useState(null); // State for the selected image

Expand Down Expand Up @@ -54,7 +55,8 @@ const OnBoardingForm = () => {
linkedin: formData.linkedin,
bio: formData.bio,
currentCompany: formData.currentCompany,
profileImageUrl: imageUrl, // Add the image URL to the document
profileImageUrl: imageUrl,
isVerified: formData.isVerified,
});

// Reset form after successful submission
Expand Down
7 changes: 7 additions & 0 deletions src/pages/AdminDashboard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

const AdminDashboard = () => {
return <div>AdminDashboard</div>;
};

export default AdminDashboard;
7 changes: 7 additions & 0 deletions src/pages/MyProfile.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

const MyProfile = () => {
return <div>MyProfile</div>;
};

export default MyProfile;
38 changes: 36 additions & 2 deletions src/pages/SignIn.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React, { useState } from "react";
import { createUserWithEmailAndPassword, signInWithPopup } from "firebase/auth";
import {
getAuth,
createUserWithEmailAndPassword,
fetchSignInMethodsForEmail,
signInWithPopup,
} from "firebase/auth";
import { auth, googleProvider } from "../config/firebase.js";
import { toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
Expand All @@ -16,7 +21,20 @@ const SignIn = () => {
toast.error("Please fill all the fields");
return;
}

const auth = getAuth();

try {
// Check if the email already exists
const signInMethods = await fetchSignInMethodsForEmail(auth, email);

if (signInMethods.length === 0) {
// Email does not exist, prompt the user to sign up
toast.error("You don't have an account yet. Please sign up first.");
return;
}

// Email exists, proceed with signing in
await createUserWithEmailAndPassword(auth, email, password);
navigate("/");
toast.success("SignedIn successfully!");
Expand All @@ -27,9 +45,25 @@ const SignIn = () => {
};
const SignInWithGoogle = async () => {
try {
const auth = getAuth();

// Sign in with Google
await signInWithPopup(auth, googleProvider);

// Check if the user's email already exists
const user = auth.currentUser;
const signInMethods = await fetchSignInMethodsForEmail(auth, user.email);

if (signInMethods.length === 0) {
// Email does not exist, sign out the user and prompt to sign up
await auth.signOut();
toast.error("You don't have an account yet. Please sign up first.");
return;
}

// Email exists, proceed with navigation
navigate("/");
toast.success("SignedIn successfully!");
toast.success("Signed in successfully!");
} catch (error) {
console.log(error);
toast.error("Error signing in");
Expand Down

0 comments on commit d6e95ec

Please sign in to comment.