Skip to content

Commit

Permalink
removed all warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ynng committed Apr 16, 2022
1 parent 972467a commit 059c0f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
5 changes: 2 additions & 3 deletions src/components/Login.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import { Link } from "react-router-dom";
import { auth, logInWithEmailAndPassword, signInWithGoogle } from "../firebase";
import { useAuthState } from "react-firebase-hooks/auth";
import "./Login.css";
Expand All @@ -8,8 +8,7 @@ import Card from "./Card";
function Login() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [user, loading, error] = useAuthState(auth);
const navigate = useNavigate();
const [user, loading] = useAuthState(auth);
useEffect(() => {
if (loading) {
// maybe trigger a loading screen
Expand Down
2 changes: 1 addition & 1 deletion src/components/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Register() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [name, setName] = useState("");
const [user, loading, error] = useAuthState(auth);
const [user, loading] = useAuthState(auth);
const register = () => {
if (!name) alert("Please enter name");
registerWithEmailAndPassword(name, email, password);
Expand Down
4 changes: 1 addition & 3 deletions src/components/Reset.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import React, { useEffect, useState } from "react";
import { useAuthState } from "react-firebase-hooks/auth";
import { useNavigate } from "react-router-dom";
import { Link } from "react-router-dom";
import Card from "./Card";
import { auth, sendPasswordReset } from "../firebase";
import "./Reset.css";
function Reset() {
const [email, setEmail] = useState("");
const [user, loading, error] = useAuthState(auth);
const navigate = useNavigate();
const [user, loading] = useAuthState(auth);
useEffect(() => {
if (loading) return;
// if (user) navigate("/dashboard");
Expand Down
27 changes: 14 additions & 13 deletions src/screens/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ export default function Dashboard() {


/* Firebase authentication */
const [user, loading, error] = useAuthState(auth);
const [user, loading] = useAuthState(auth);
const [name, setName] = useState("");
const fetchUserName = async () => {
try {
const q = query(collection(db, "users"), where("uid", "==", user?.uid));
const doc = await getDocs(q);
const data = doc.docs[0].data();
setName(data.name);
} catch (err) {
console.error(err);
alert("An error occured while fetching user data");
}
};


useEffect(() => {
const fetchUserName = async () => {
try {
const q = query(collection(db, "users"), where("uid", "==", user?.uid));
const doc = await getDocs(q);
const data = doc.docs[0].data();
setName(data.name);
} catch (err) {
console.error(err);
alert("An error occured while fetching user data");
}
};

if (loading) return;
if (!user) {
setName("Not logged in");
Expand Down

0 comments on commit 059c0f5

Please sign in to comment.