Skip to content

Commit

Permalink
Fixed all problem
Browse files Browse the repository at this point in the history
  • Loading branch information
rumon5h committed Dec 26, 2022
1 parent 2905075 commit f7ce487
Show file tree
Hide file tree
Showing 8 changed files with 18,272 additions and 231 deletions.
18,392 changes: 18,220 additions & 172 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<script src="https://kit.fontawesome.com/c67cd56b75.js" crossorigin="anonymous"></script>
<script src="https://kit.fontawesome.com/e98990cd24.js" crossorigin="anonymous"></script>
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand Down
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import PrivateRoute from './components/PrivateRoute/PrivateRoute';
import BuyCourse from './components/BuyCourse/BuyCourse';

function App() {


return (
<div className='max-w-7xl mx-auto '>
<Navbar></Navbar>
Expand Down
32 changes: 0 additions & 32 deletions src/components/GoogleAuth/GoogleAuth.js
Original file line number Diff line number Diff line change
@@ -1,32 +0,0 @@
import React from "react";
import { useSignInWithGoogle } from "react-firebase-hooks/auth";
import toast from "react-hot-toast";
import { useNavigate } from "react-router-dom";
import auth from "../../firebase.init";
import Loading from "../Loading/Loading";

const GoogleAuth = () => {
const [signInWithGoogle, user, loading, error] = useSignInWithGoogle(auth);
const navigate = useNavigate();

if (loading) {
return <Loading />;
}
if (user) {
return navigate("/home");
}

return (
<>
<button
onClick={() => signInWithGoogle()}
className="btn btn-outline w-[300px] my-2"
>
Continue with Google
</button>
{error && toast.error(error.message, { id: "gError" })}
</>
);
};

export default GoogleAuth;
29 changes: 21 additions & 8 deletions src/components/Login/Login.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useEffect } from "react";
import { useSignInWithEmailAndPassword } from "react-firebase-hooks/auth";
import { useSignInWithEmailAndPassword, useSignInWithGoogle } from "react-firebase-hooks/auth";
import toast from "react-hot-toast";
import { Link, useLocation, useNavigate } from "react-router-dom";
import auth from "../../firebase.init";
import GoogleAuth from "../GoogleAuth/GoogleAuth";
import Loading from "../Loading/Loading";

const Login = () => {
const [signInWithGoogle, gUser, gLoading, gError] = useSignInWithGoogle(auth);
const [signInWithEmailAndPassword, user, loading, error] =
useSignInWithEmailAndPassword(auth);
const navigate = useNavigate();
Expand All @@ -22,15 +22,21 @@ const Login = () => {
};

useEffect(() => {
if (user) {
if (user || gUser) {
navigate(from, { replace: true });
}
},[user, from, navigate]);
},[user, from, navigate, gUser]);

if (loading) {
return <Loading />;
}


useEffect(() => {

if(loading || gLoading) {
return () => {
<Loading/>
};
}
},[loading, gLoading]);


return (
Expand All @@ -50,6 +56,8 @@ const Login = () => {
className="input input-bordered"
/>
{error && toast.error(error.message, { id: "error3" })}
{gError && toast.error(gError.message, { id: "gError" })}

</div>
<div className="form-control my-2">
<label className="label">
Expand All @@ -71,7 +79,12 @@ const Login = () => {
</p>
<input className="btn w-full " type="submit" value="LogIn" />
</form>
<GoogleAuth />
<button
onClick={() => signInWithGoogle()}
className="btn btn-outline w-[300px] my-2"
>
Continue with Google
</button>
</div>
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions src/components/Navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import React from "react";
import { useAuthState } from "react-firebase-hooks/auth";
import { Link } from "react-router-dom";
import auth from "../../firebase.init";
import Loading from "../Loading/Loading";

const Navbar = () => {
const [user, loading] = useAuthState(auth);

if (loading) {
return <Loading />;
return "";
}

const logout = () => {
Expand Down
28 changes: 18 additions & 10 deletions src/components/SignUp/SignUp.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { useEffect, useState } from "react";
import { Link, useLocation, useNavigate } from "react-router-dom";
import auth from "../../firebase.init";
import { useCreateUserWithEmailAndPassword } from "react-firebase-hooks/auth";
import { useCreateUserWithEmailAndPassword, useSignInWithGoogle } from "react-firebase-hooks/auth";
import toast from "react-hot-toast";
import { useUpdateProfile } from "react-firebase-hooks/auth";
import { async } from "@firebase/util";
import Loading from "../Loading/Loading";
import GoogleAuth from "../GoogleAuth/GoogleAuth";
import auth from "../../firebase.init";

const SignUp = () => {
const [signInWithGoogle, gUser, gLoading, gError] = useSignInWithGoogle(auth);
const [error2, setError2] = useState(null);
const navigate = useNavigate();
const location = useLocation();
Expand All @@ -35,16 +34,18 @@ const SignUp = () => {
};

useEffect(() => {
if (loading || updating) {
return <Loading />;
if (loading || updating || gLoading) {
return () => {
<Loading/>
};
}
},[loading, updating])
},[loading, updating, gLoading])

useEffect(() => {
if (user) {
if (user || gUser) {
navigate(from, { replace: true });
}
}, [user, from, navigate]);
}, [user, from, navigate, gUser]);



Expand Down Expand Up @@ -90,6 +91,8 @@ const SignUp = () => {
/>
{error && toast.error(error.message, { id: "error" })}
{uError && toast.error(uError.message, { id: "uError" })}
{gError && toast.error(gError.message, { id: "gError" })}

</div>
<div className="form-control my-2">
<label className="label">
Expand All @@ -116,7 +119,12 @@ const SignUp = () => {
</p>
<input className="btn w-full " type="submit" value="SignUp" />
</form>
<GoogleAuth />
<button
onClick={() => signInWithGoogle()}
className="btn btn-outline w-[300px] my-2"
>
Continue with Google
</button>
</div>
</div>
);
Expand Down
15 changes: 9 additions & 6 deletions src/firebase.init.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";

// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: process.env.REACT_APP_apiKey,
authDomain: process.env.REACT_APP_authDomain,
projectId: process.env.REACT_APP_projectId,
storageBucket: process.env.REACT_APP_storageBucket,
messagingSenderId: process.env.REACT_APP_messagingSenderId,
appId: process.env.REACT_APP_appId,
apiKey: "AIzaSyD2k-5PmGq_u2XZEf9DcRbnxX2S6FhMSsk",
authDomain: "learnwithrumon.firebaseapp.com",
projectId: "learnwithrumon",
storageBucket: "learnwithrumon.appspot.com",
messagingSenderId: "314388553216",
appId: "1:314388553216:web:a78efe3815a715753202e5",
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);

const auth = getAuth(app);

export default auth;

0 comments on commit f7ce487

Please sign in to comment.