Skip to content

Commit

Permalink
Fix: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
sarkartanmay393 committed Mar 2, 2023
1 parent 57dd072 commit 0a65ccb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
6 changes: 4 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Loader from "./components/Loader";
import { FaArrowCircleUp } from "react-icons/fa";
import { useSnackbar } from "notistack";
import logo from "./assets/logo.png";
import {Switch, Route, Link, useHistory, Redirect} from "react-router-dom";
import {Switch, Route, useHistory} from "react-router-dom";
import LoginScreen from './pages/Login';
import SignupScreen from './pages/Signup';
import AnimatedButton from "./components/AnimatedButton";
Expand Down Expand Up @@ -94,8 +94,10 @@ function App() {
const unsubscribe = auth.onAuthStateChanged((authUser) => {
if (authUser) {
setUser(authUser);
history.push('/dummygram/');
} else {
setUser(null);
history.push('/dummygram/login');
}

});
Expand Down Expand Up @@ -356,7 +358,7 @@ function App() {
)}
</div>
</div> :
<Redirect to='/dummygram/login'></Redirect>
<></>
}
</Route>

Expand Down
35 changes: 6 additions & 29 deletions src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React, {useState, useEffect} from 'react';
import { getModalStyle, useStyles } from '../App';
import { Input } from "@mui/material";
import AnimatedButton from "../components/AnimatedButton";
import { auth } from "../lib/firebase";
import { auth, googleProvider, facebookProvider } from "../lib/firebase";
import { useSnackbar } from "notistack";
import { useHistory } from 'react-router-dom';



Expand All @@ -15,8 +16,6 @@ const LoginScreen = () => {
const [password, setPassword] = useState("");
const [user, setUser] = useState(null);

// const [loggingIn, setLoggingIn] = useState(false);

const buttonStyle = {
background: "linear-gradient(40deg, #e107c1, #59afc7)",
borderRadius: "20px",
Expand All @@ -26,49 +25,30 @@ const LoginScreen = () => {
};

const { enqueueSnackbar } = useSnackbar();


// useEffect(() => {
// const unsubscribe = auth.onAuthStateChanged((authUser) => {
// if (authUser) {
// // user has logged in
// setUser(authUser);
// } else {
// // user has logged out
// setUser(null);
// }
// });
// return () => {
// // perform some cleanup actions
// unsubscribe();
// };
// }, [user, username]);
const history = useHistory();

const signIn = (e) => {
e.preventDefault();
// setLoggingIn(true);
auth
.signInWithEmailAndPassword(email, password)
.then(() => {
enqueueSnackbar("Login successful!", {
variant: "success",
});
window.location.href = '/';
// history.push('/dummygram/');
})
.catch((error) =>
enqueueSnackbar(error.message, {
variant: "error",
})
)
.finally(() => {
// setLoggingIn(false);
});
};


const signInWithGoogle = (e) => {
e.preventDefault();
setLoggingIn(true);
auth
.signInWithPopup(googleProvider)
.then(() => {
Expand All @@ -82,33 +62,30 @@ const LoginScreen = () => {
})
)
.finally(() => {
setLoggingIn(false);
});
};

const signInWithFacebook = (e) => {
e.preventDefault();
setLoggingIn(true);
auth
.signInWithPopup(facebookProvider)
.then(() => {
enqueueSnackbar("Login successful!", {
variant: "success",
});
setOpenSignIn(false);
})
.catch((error) =>
enqueueSnackbar(error.message, {
variant: "error",
})
)
.finally(() => {
setLoggingIn(false);
});
};

return (
<div style={{
<div
style={{
display: "flex",
alignContent: "center",
justifyContent: "center",
Expand Down
7 changes: 6 additions & 1 deletion src/pages/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React, {useState, useEffect} from 'react';
import { getModalStyle, useStyles } from '../App';
import { Input } from "@mui/material";
import AnimatedButton from "../components/AnimatedButton";
import {auth, storage,} from "../lib/firebase";
import {auth, storage, googleProvider, facebookProvider } from "../lib/firebase";
import { useSnackbar } from "notistack";



const SignupScreen = () => {
Expand All @@ -26,6 +28,9 @@ const SignupScreen = () => {
},
};

const { enqueueSnackbar } = useSnackbar();


const handleChange = (e) => {
if (e.target.files[0]) {
setImage(e.target.files[0]);
Expand Down

0 comments on commit 0a65ccb

Please sign in to comment.