diff --git a/src/components/login.jsx b/src/components/login.jsx
index 45217f9..a07697c 100644
--- a/src/components/login.jsx
+++ b/src/components/login.jsx
@@ -1,52 +1,19 @@
import React, { useState } from 'react';
import '../App.css';
-import mainImg from '../assets/codeit-logo.png'
-// import './bg-main.css'
-import '../styles/signup.css'
-import { login } from '../utilities/Login'
+import mainImg from '../assets/codeit-logo.png';
+import '../styles/signup.css';
+import { signInWithEmailAndPassword, signInWithPopup } from "firebase/auth";
import { useNavigate } from 'react-router-dom';
-import { useAuthValue } from '../utilities/AuthContext'
-import { auth, db } from "../utilities/firebase";
-import { signInWithEmailAndPassword } from "firebase/auth";
-import { redirect } from 'react-router-dom'
-import { writeBatch, doc, addDoc, collection } from 'firebase/firestore';
+import { useAuthValue } from '../utilities/AuthContext';
+import { auth, provider } from '../firebaseConfig'
export default function Login() {
-
- // async function importJSONToFirestore(collectionName, jsonArray) {
- // try {
- // const batch = writeBatch(db);
- // jsonArray.forEach((jsonObject) => {
- // // Generate a new document reference for each JSON object
- // addDoc(collection(db, collectionName), jsonObject);
- // // batch.set(newDocRef, jsonObject);
- // });
-
- // // Commit the batch
- // // await batch.commit();
-
- // // console.log('Import completed successfully.');
- // } catch (error) {
- // console.error('Error importing data to Firestore:', error);
- // }
- // }
-
- // Example usage
-
-
-
-
- const collectionName = 'problems'; // Replace with your desired collection name
-
-
-
const [loginData, setLoginData] = useState({
email: '',
password: '',
});
const navigate = useNavigate();
- const { currentUser } = useAuthValue()
- // // console.log(loginData.email)
+ const { currentUser } = useAuthValue();
const handleInputChange = (event) => {
const { name, value } = event.target;
@@ -56,40 +23,25 @@ export default function Login() {
}));
};
- const login = async (email, password, e) => {
- // e.preventDefault();
- // setError("");
- // debugger
+ const login = async (email, password) => {
signInWithEmailAndPassword(auth, email, password)
- .then((res) => {
- // debugger
- // console.log(res.user);
- // debugger
- navigate('/dashboard')
+ .then(() => {
+ navigate('/dashboard');
})
.catch((err) => alert(err.message));
-
- // setEmail("");
- // setPassword("");
- // setConfirmPassword("");
};
- // const handleSubmit = async (event) => {
- // event.preventDefault();
- // const { email, password } = loginData;
-
-
- // const params = new URLSearchParams();
- // params.append('email', email);
- // params.append('password', password);
-
- // const url = `register?${params}`;
-
- // let postReq = await fetch(url)
- // // console.log("hiiii")
- // let res = await postReq.json()
- // // console.log('Logged in with', res.body);
- // };
+ const loginWithGoogle = async () => {
+ signInWithPopup(auth, provider)
+ .then((result) => {
+ // User logged in with Google
+ navigate('/dashboard');
+ })
+ .catch((error) => {
+ console.error(error);
+ alert('Google sign-in failed!');
+ });
+ };
return (
@@ -129,18 +81,14 @@ export default function Login() {
/>
-
-
-
+
or
-
-
Create your account
+
Create your account