Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
EyadHeg committed Dec 13, 2024
1 parent c6b9f50 commit 9db7440
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 53 deletions.
83 changes: 44 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"@testing-library/user-event": "^13.5.0",
"axios": "^1.7.8",
"chart.js": "^4.4.7",
"firebase": "^11.0.2",
"client": "file:",
"firebase": "^11.1.0",
"font-awesome": "^4.7.0",
"openai": "^4.75.0",
"react": "^18.3.1",
Expand Down
26 changes: 20 additions & 6 deletions src/components/Singup/index.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import { createUserWithEmailAndPassword, updateProfile } from "firebase/auth"; // استيراد updateProfile
import { createUserWithEmailAndPassword, updateProfile } from "firebase/auth";
import { ref, set } from "firebase/database"; // Import Realtime Database functions
import styles from "./styles.module.css";
import { auth } from "../../firebaseConfig"; // استيراد firebase auth
import { auth, realTimeDb } from "../../firebaseConfig"; // Import realTimeDb

const Signup = () => {
const [data, setData] = useState({
Expand Down Expand Up @@ -30,13 +31,26 @@ const Signup = () => {
return;
}
try {
// استخدام Firebase Auth لإنشاء حساب جديد
// Create the user with Firebase Auth
const userCredential = await createUserWithEmailAndPassword(auth, data.email, data.password);
const user = userCredential.user;

// تحديث اسم المستخدم
// Update the user's profile with the full name
await updateProfile(user, { displayName: data.fullName });


// Store user data in Firebase Realtime Database
const userRef = ref(realTimeDb, 'Users/' + user.uid); // Use the user's UID as the unique key
await set(userRef, {
fullName: data.fullName,
email: data.email,
age: data.age,
weight: data.weight,
gender: data.gender,
height: data.height,
healthConditions: data.healthConditions,
});

// Navigate to the login page after successful signup
navigate("/login");
} catch (error) {
setError(error.message);
Expand Down Expand Up @@ -154,4 +168,4 @@ const Signup = () => {
);
};

export default Signup;
export default Signup;
18 changes: 11 additions & 7 deletions src/firebaseConfig.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { initializeApp } from "firebase/app";
import { initializeApp } from "firebase/app"; // Initialize Firebase app first
import { getAuth, GoogleAuthProvider, FacebookAuthProvider } from "firebase/auth";
import { getFirestore } from "firebase/firestore"; // استيراد Firestore
import { getFirestore } from "firebase/firestore";
import { getDatabase } from "firebase/database"; // For Realtime Database

// Firebase configuration object
const firebaseConfig = {
apiKey: "AIzaSyDc1iS4NX2um7sqJuYRSll9Il_7V6g6LsE",
authDomain: "graduatinproject.firebaseapp.com",
projectId: "graduatinproject",
storageBucket: "graduatinproject.appspot.com", // تأكد من صحة الـ storageBucket
storageBucket: "graduatinproject.appspot.com",
messagingSenderId: "361149223809",
appId: "1:361149223809:web:58467e248f81422f97ce80",
measurementId: "G-NRG6TMTB8Q",
databaseURL: "https://graduatinproject-default-rtdb.europe-west1.firebasedatabase.app", // Add this line
};

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

// Get Firebase services
// Now initialize Firebase services (auth, firestore, etc.)
const auth = getAuth(app);
const googleProvider = new GoogleAuthProvider();
const facebookProvider = new FacebookAuthProvider();
const db = getFirestore(app); // تهيئة Firestore
const db = getFirestore(app); // Firestore
const realTimeDb = getDatabase(app); // Realtime Database

export { auth, googleProvider, facebookProvider, db }; // تصدير auth و db و المزودين
export { auth, googleProvider, facebookProvider, db, realTimeDb };

0 comments on commit 9db7440

Please sign in to comment.