diff --git a/src/AppRouter.jsx b/src/AppRouter.jsx
index e751fd5..3606d2f 100644
--- a/src/AppRouter.jsx
+++ b/src/AppRouter.jsx
@@ -10,7 +10,7 @@ const Dashboard = lazy(() => import('./pages/dashboard/Dashboard'));
const ErrorPage = lazy(() => import('./pages/error/Error'));
const Login = lazy(() => import('./component/login/Login'));
const Logout = lazy(() => import('./pages/logout/Logout'));
-const Profile = lazy(() => import('./pages/profile/Profile'));
+const Profile = lazy(() => import('./component/profile/Profile'));
const Administration = lazy(() => import('./pages/administration/Administration'));
const Home = lazy(() => import('./pages/home/Home'));
const SignUp = lazy(() => import('./pages/signup/SignUp'));
diff --git a/src/component/deleteAccount/DeleteAccount.jsx b/src/component/deleteAccount/DeleteAccount.jsx
index b56b20a..befe2cd 100644
--- a/src/component/deleteAccount/DeleteAccount.jsx
+++ b/src/component/deleteAccount/DeleteAccount.jsx
@@ -1,6 +1,6 @@
// src/component/DeleteAccount.jsx
import { useState, useContext } from 'react';
-import { auth } from '../../firebaseConfig';
+import { auth } from '../../utils/firebaseConfig';
import { deleteUser, reauthenticateWithCredential, EmailAuthProvider } from 'firebase/auth';
import { useNavigate } from 'react-router-dom';
import { AuthContext } from '../../context/AuthContext'; // Import AuthContext for å få tilgang til logout-funksjonen
diff --git a/src/component/login/Login.jsx b/src/component/login/Login.jsx
index 4288576..8938c8d 100644
--- a/src/component/login/Login.jsx
+++ b/src/component/login/Login.jsx
@@ -1,7 +1,7 @@
import { useState, useContext, useEffect } from 'react';
import { AuthContext } from '../../context/AuthContext';
import { useNavigate } from 'react-router-dom';
-import { auth } from '../../firebaseConfig';
+import { auth } from '../../utils/firebaseConfig';
import { signInWithEmailAndPassword } from 'firebase/auth';
import '../../component/login/login.css';
diff --git a/src/component/profile/Profile.jsx b/src/component/profile/Profile.jsx
new file mode 100644
index 0000000..cdceb4b
--- /dev/null
+++ b/src/component/profile/Profile.jsx
@@ -0,0 +1,28 @@
+// src/component/profile/Profile.jsx
+import useProfile from '../../hooks/useProfile';
+
+const Profile = () => {
+ const { profileData, loading } = useProfile();
+
+ if (loading) {
+ return
Loading...
;
+ }
+
+ if (!profileData) {
+ return No profile data found.
;
+ }
+
+ return (
+
diff --git a/src/pages/profile/Profile.jsx b/src/pages/profile/Profile.jsx
deleted file mode 100644
index 9f40de0..0000000
--- a/src/pages/profile/Profile.jsx
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-const Profile = () => {
- return (
-
Profile
- )
-}
-
-export default Profile
\ No newline at end of file
diff --git a/src/pages/profile/profile.css b/src/pages/profile/profile.css
deleted file mode 100644
index e69de29..0000000
diff --git a/src/pages/signup/SignUp.jsx b/src/pages/signup/SignUp.jsx
index b4c515e..5bd9943 100644
--- a/src/pages/signup/SignUp.jsx
+++ b/src/pages/signup/SignUp.jsx
@@ -1,16 +1,13 @@
// src/component/signup/SignUp.jsx
import { useState } from 'react';
-import { auth, firestore } from '../../firebaseConfig';
-import { createUserWithEmailAndPassword, signInWithEmailAndPassword } from 'firebase/auth';
-import { collection, addDoc } from 'firebase/firestore';
+import { auth, firestore, storage } from '../../utils/firebaseConfig'; // Importer nødvendige moduler
+import { createUserWithEmailAndPassword } from 'firebase/auth';
+import { doc, setDoc } from 'firebase/firestore'; // Importer setDoc for å oppdatere dokumenter
import { useNavigate } from 'react-router-dom';
import { signUpSchema } from '../../assets/validationSchema';
import CityAutocomplete from '../../component/AutoComplete/CityAutoComplete';
import CountryAutocomplete from '../../component/AutoComplete/CountryAutoComplete';
-import { storage } from '../../firebaseConfig';
-import { ref, uploadBytes, getDownloadURL } from 'firebase/storage';
-
-
+import { ref, uploadBytes, getDownloadURL } from 'firebase/storage'; // Importer for opplasting av bilder
import './signup.css';
const SignUp = () => {
@@ -66,17 +63,20 @@ const SignUp = () => {
try {
await signUpSchema.validate(formData, { abortEarly: false });
+ // Opprett bruker med Firebase Authentication
const userCredential = await createUserWithEmailAndPassword(auth, formData.email, formData.password);
const user = userCredential.user;
let profileImageUrl = '';
+ // Last opp profilbilde hvis det er valgt
if (profileImage) {
const imageRef = ref(storage, `profileImages/${user.uid}`);
await uploadBytes(imageRef, profileImage);
- profileImageUrl = await getDownloadURL(imageRef);
+ profileImageUrl = await getDownloadURL(imageRef); // Hent URL for det opplastede bildet
}
- await addDoc(collection(firestore, 'users'), {
+ // Opprett eller oppdater dokumentet for brukeren i Firestore
+ await setDoc(doc(firestore, 'users', user.uid), {
uid: user.uid,
name: formData.name,
email: formData.email,
@@ -86,14 +86,13 @@ const SignUp = () => {
postalPlace: formData.postalPlace,
city: formData.city,
country: formData.country,
- profileImage: profileImageUrl,
+ profileImage: profileImageUrl, // Lagre URL for profilbilde
});
setSuccess('User registered successfully!');
- await signInWithEmailAndPassword(auth, formData.email, formData.password);
-
- navigate('/dashboard');
+ // Naviger til profilen etter registrering
+ navigate('/profile');
} catch (err) {
if (err.name === 'ValidationError') {
@@ -243,4 +242,10 @@ const SignUp = () => {
);
};
-export default SignUp;
\ No newline at end of file
+export default SignUp;
+
+
+
+
+
+
diff --git a/src/utils/fireBaseStorage.js b/src/utils/fireBaseStorage.js
new file mode 100644
index 0000000..36bc19f
--- /dev/null
+++ b/src/utils/fireBaseStorage.js
@@ -0,0 +1,12 @@
+import { getStorage } from 'firebase/storage';
+import { logError } from './firebaseConfig';
+
+let storage;
+
+try {
+ storage = getStorage();
+} catch (error) {
+ logError('Storage', error);
+}
+
+export { storage };
diff --git a/src/utils/firebaseAuth.js b/src/utils/firebaseAuth.js
new file mode 100644
index 0000000..eb654af
--- /dev/null
+++ b/src/utils/firebaseAuth.js
@@ -0,0 +1,12 @@
+import { getAuth } from 'firebase/auth';
+import { logError } from './firebaseConfig';
+
+let auth;
+
+try {
+ auth = getAuth();
+} catch (error) {
+ logError('Authentication', error);
+}
+
+export { auth };
diff --git a/src/utils/firebaseConfig.js b/src/utils/firebaseConfig.js
new file mode 100644
index 0000000..fb87325
--- /dev/null
+++ b/src/utils/firebaseConfig.js
@@ -0,0 +1,43 @@
+// firebaseConfig.js
+import { initializeApp } from 'firebase/app';
+import { getFirestore } from 'firebase/firestore';
+import { getAuth } from 'firebase/auth';
+import { getAnalytics } from 'firebase/analytics';
+import { getStorage } from 'firebase/storage'; // Importer getStorage fra Firebase
+
+// Firebase-konfigurasjon
+const firebaseConfig = {
+ apiKey: "AIzaSyBf-UV2wzdvuGdUdAb4dUVKQln6hYJWtJY",
+ authDomain: "bookingpage-bef4a.firebaseapp.com",
+ projectId: "bookingpage-bef4a",
+ storageBucket: "bookingpage-bef4a.appspot.com",
+ messagingSenderId: "676485037932",
+ appId: "1:676485037932:web:91736d92b774a628a23d49",
+ measurementId: "G-6JTVF4PKK8"
+};
+
+// Initialiser Firebase-appen
+let app;
+try {
+ app = initializeApp(firebaseConfig);
+} catch (error) {
+ console.error("Error initializing Firebase app:", error);
+}
+
+// Initialiser Firestore
+const firestore = getFirestore(app);
+
+// Initialiser Auth
+const auth = getAuth(app);
+
+// Initialiser Storage
+const storage = getStorage(app);
+
+// Initialiser Analytics
+const analytics = getAnalytics(app);
+
+// Eksporter nødvendige moduler
+export { firestore, auth, storage, analytics };
+
+
+
diff --git a/src/utils/firebaseFireStorm.js b/src/utils/firebaseFireStorm.js
new file mode 100644
index 0000000..f6b3492
--- /dev/null
+++ b/src/utils/firebaseFireStorm.js
@@ -0,0 +1,12 @@
+import { getFirestore } from 'firebase/firestore';
+import { logError } from './firebaseConfig';
+
+let firestore;
+
+try {
+ firestore = getFirestore();
+} catch (error) {
+ logError('Firestore', error);
+}
+
+export { firestore };
diff --git a/src/utils/firebaseUtils.js b/src/utils/firebaseUtils.js
new file mode 100644
index 0000000..496e758
--- /dev/null
+++ b/src/utils/firebaseUtils.js
@@ -0,0 +1,64 @@
+import { firestore, storage } from './firebaseConfig'; // Pass på at banen er korrekt
+import { doc, getDoc, setDoc } from 'firebase/firestore';
+import { ref, uploadBytes, getDownloadURL } from 'firebase/storage';
+
+// Hent brukerdata fra Firestore
+export const getUserData = async (userId) => {
+ try {
+ const userDoc = await getDoc(doc(firestore, 'users', userId));
+ if (userDoc.exists()) {
+ return userDoc.data();
+ } else {
+ throw new Error("User not found");
+ }
+ } catch (error) {
+ console.error("Error fetching user data:", error);
+ throw error;
+ }
+};
+
+// Oppdater brukerdata i Firestore
+export const updateUserData = async (userId, data) => {
+ // Validerer data før oppdatering
+ if (!data || typeof data !== 'object') {
+ throw new Error("Invalid data provided");
+ }
+
+ try {
+ await setDoc(doc(firestore, 'users', userId), data, { merge: true });
+ return "User data updated successfully"; // Tilbakemelding
+ } catch (error) {
+ console.error("Error updating user data:", error);
+ throw error;
+ }
+};
+
+// Last opp profilbilde til Firebase Storage og hent URL
+export const uploadProfileImage = async (userId, file) => {
+ // Validerer filen før opplasting
+ if (!file || !(file instanceof Blob)) {
+ throw new Error("Invalid file provided");
+ }
+
+ try {
+ const imageRef = ref(storage, `profileImages/${userId}`);
+ await uploadBytes(imageRef, file);
+ const imageUrl = await getDownloadURL(imageRef);
+ return imageUrl; // Returner kun URL-en som en string
+ } catch (error) {
+ console.error("Error uploading profile image:", error);
+ throw error;
+ }
+};
+
+// Hent profilbilde-URL for bruker
+export const getProfileImageUrl = async (userId) => {
+ try {
+ const imageRef = ref(storage, `profileImages/${userId}`);
+ const imageUrl = await getDownloadURL(imageRef);
+ return imageUrl;
+ } catch (error) {
+ console.error("Error fetching profile image URL:", error);
+ throw error;
+ }
+};
\ No newline at end of file
diff --git a/vite.config copy.js b/vite.config copy.js
new file mode 100644
index 0000000..ecb5e8d
--- /dev/null
+++ b/vite.config copy.js
@@ -0,0 +1,65 @@
+// vite.config.js
+import { defineConfig } from 'vite';
+import react from '@vitejs/plugin-react-swc';
+import { visualizer } from 'rollup-plugin-visualizer';
+import { VitePWA } from 'vite-plugin-pwa';
+
+// Setter base-URL basert på 'mode'-argumentet
+export default defineConfig(({ mode }) => {
+ const base = mode === 'production' ? '/bookingapp/' : '/';
+
+ return {
+ plugins: [
+ react(),
+ visualizer({ open: true }), // Åpner en grafisk rapport automatisk etter bygging
+ VitePWA({
+ registerType: 'autoUpdate',
+ includeAssets: ['favicon.ico', 'robots.txt', 'apple-touch-icon.png'],
+ manifest: {
+ name: 'Booking App',
+ short_name: 'Booking',
+ theme_color: '#ffffff',
+ icons: [
+ {
+ src: 'icon-192x192.png',
+ sizes: '192x192',
+ type: 'image/png',
+ },
+ {
+ src: 'icon-512x512.png',
+ sizes: '512x512',
+ type: 'image/png',
+ },
+ ],
+ },
+ }),
+ ],
+ base, // Dynamisk base-URL
+ build: {
+ outDir: 'dist',
+ rollupOptions: {
+ output: {
+ manualChunks(id) {
+ if (id.includes('node_modules')) {
+ return id.toString().split('node_modules/')[1].split('/')[0].toString();
+ }
+ },
+ },
+ },
+ },
+ server: {
+ hmr: {
+ overlay: false,
+ },
+ historyApiFallback: true,
+ },
+ optimizeDeps: {
+ include: [
+ 'firebase/app',
+ 'firebase/auth',
+ 'firebase/firestore',
+ 'firebase/analytics'
+ ]
+ }
+ };
+});