Skip to content

Commit

Permalink
Fix deployment issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lokeshwar777 committed Aug 22, 2024
1 parent 67602ef commit 11ec0b9
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 28 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
VITE_APP_FIREBASE_APP_ID=<FIREBASE_APP_ID>
VITE_APP_FIREBASE_MEASUREMENTID=<FIREBASE_MEASUREMENTID>
VITE_APP_DATABASE_URL=<FIREBASE_DATABASE_URL>
VITE_APP_FIREBASE_STORAGE_BUCKET=<VITE_APP_FIREBASE_STORAGE_BUCKET>
VITE_APP_FIREBASE_FCM_VAPID_KEY=<FIREBASE_VAPID_KEY>
VITE_APP_USE_EMULATOR=<USE_EMULATOR>
CYPRESS_PROJECT_ID=<CYPRESS_PROJECT_ID>
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
node: [18]
containers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# containers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

env:
CI: false
Expand Down
4 changes: 2 additions & 2 deletions database.rules.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"rules": {
".read": false,
".write": false
".read": true,
".write": true
}
}
120 changes: 95 additions & 25 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import "firebase/compat/database"; // <- needed if using firebase rtdb
import "firebase/compat/firestore"; // <- needed if using firestore
import "firebase/compat/database";
import "firebase/compat/firestore";
import "firebase/compat/storage";
import "firebase/compat/functions";
import "firebase/compat/analytics";
Expand All @@ -13,43 +13,36 @@ import { onMessage } from "firebase/messaging";
const firebaseConfig = {
apiKey: import.meta.env.VITE_APP_FIREBASE_API_KEY,
authDomain: import.meta.env.VITE_APP_AUTH_DOMAIN,
databaseURL: `https://${
import.meta.env.VITE_APP_FIREBASE_PROJECT_ID
}.firebaseio.com`,
databaseURL: import.meta.env.VITE_APP_DATABASE_URL,
projectId: import.meta.env.VITE_APP_FIREBASE_PROJECT_ID,
storageBucket: `${import.meta.env.VITE_APP_FIREBASE_PROJECT_ID}.appspot.com`,
storageBucket: import.meta.env.VITE_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: import.meta.env.VITE_APP_FIREBASE_MESSAGING_SENDER_ID,
appId: import.meta.env.VITE_APP_FIREBASE_APP_ID,
measurementId: import.meta.env.VITE_APP_FIREBASE_MEASUREMENTID
};

//console.log("firebaseConfig", firebaseConfig);
// console.log("firebaseConfig", firebaseConfig);

export const onlineFirebaseApp = initializeApp(firebaseConfig, "secondary");

// Initialize firebase instance
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore(); // <- needed if using firestor
const db = firebase.firestore();

if (import.meta.env.VITE_APP_USE_EMULATOR === "true") {
console.log("Using emulator");
firebase.firestore().useEmulator("localhost", 8080);
firebase.auth().useEmulator("http://localhost:9099", {
disableWarnings: true
});
firebase
.auth()
.useEmulator("http://localhost:9099", { disableWarnings: true });
firebase.database().useEmulator("localhost", 9000);
firebase.functions().useEmulator("localhost", 5001);
db.settings({
// experimentalForceLongPolling: true, !! Not necessary.
merge: true
});
// firebase.functions().useEmulator("localhost", 5001);
db.settings({ merge: true });
}

// Initialize other services on firebase instance
firebase.firestore(); // <- needed if using firestore
export const functions = firebase.functions();

let firebase_messaging;
export const functions = firebase.functions();
function requestPermission() {
console.log("Requesting permission...");
Notification.requestPermission().then(permission => {
Expand All @@ -63,20 +56,22 @@ function requestPermission() {
})
.then(curToken => {
if (curToken) {
console.log("curToken", curToken);
console.log("FCM token:", curToken);
} else {
console.log("Error in getting token");
console.log("Error in getting FCM token.");
}
})
.catch(err => console.log(err));
.catch(err => console.log("FCM token error:", err));
} else {
console.log("messaging not supported");
console.log("Messaging not supported.");
}
}
});
}
requestPermission();
// Retrieve Firebase Messaging object.
const checkMessaging = false; // set true to check messaging
if (checkMessaging) {
requestPermission();
}

export const onMessageListener = () =>
new Promise(resolve => {
Expand All @@ -87,4 +82,79 @@ export const onMessageListener = () =>

export const messaging = firebase_messaging;

const testAuth = () => {
firebase
.auth()
.signInAnonymously()
.then(() => {
console.log("Auth connected and signed in anonymously.");
})
.catch(error => {
console.error("Error with Auth:", error);
});
};

const testFirestore = () => {
const docRef = db.collection("testConnection").doc("testDoc");
docRef
.set({ test: "This is a test data" })
.then(() => {
console.log("Firestore connected and data written.");
return docRef.get();
})
.then(doc => {
if (doc.exists) {
console.log("Firestore data read:", doc.data());
} else {
console.log("No such document in Firestore.");
}
})
.catch(error => {
console.error("Error with Firestore:", error);
});
};

const testRealtimeDatabase = () => {
const dbRef = firebase.database().ref("testConnection");
dbRef
.set({ test: "This is a test data" })
.then(() => {
console.log("Realtime Database connected and data written.");
return dbRef.once("value");
})
.then(snapshot => {
console.log("Realtime Database data read:", snapshot.val());
})
.catch(error => {
console.error("Error with Realtime Database:", error);
});
};

const testStorage = () => {
const storageRef = firebase
.storage()
.ref()
.child("testConnection/testFile.txt");
storageRef
.putString("This is a test file")
.then(snapshot => {
console.log("Storage connected and file uploaded.", snapshot);
return storageRef.getDownloadURL();
})
.then(url => {
console.log("Storage file URL:", url);
})
.catch(error => {
console.error("Error with Storage:", error);
});
};

const checkFirebaseServices = false; // set true to run all tests for checking whether your firebase services are connected and working properly
if (checkFirebaseServices) {
testAuth();
testRealtimeDatabase();
testFirestore();
testStorage();
}

export default firebase;
7 changes: 7 additions & 0 deletions src/store/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ export const setUpInitialData =
}
);

// Create organisation handle
await firestore.collection("org_users").doc(`${org_handle}_${userData.uid}`).set({
uid: userData.uid,
org_handle: org_handle,
permissions: [3]
});

const timeOutID = setTimeout(() => {
firebase
.updateProfile(
Expand Down

0 comments on commit 11ec0b9

Please sign in to comment.