-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incompatible Firebase 9 Modular Mode #262
Comments
I've just started getting this error too. Also updating to Firebase 9. I'm not even using Firestore. I'm using Firebase Realtime DB for my data store. I was only using react-admin-firebase for the authentication part. Not to worry. I simply asked ChatGPT to write me a new, standalone authProvider for Firebase 9 and problem solved. I can actually remove react-admin-firebase from build now. I can post the code if you think it will be of any help to you. |
@brownieboy Would be great if you can post the code! So now you don't need the react-admin-firebase? |
As requested, this is my authProvider.js file: import { getAuth, signInWithEmailAndPassword, signOut } from 'firebase/auth';
const authProvider = {
login: async ({ username, password }) => {
try {
const auth = getAuth();
await signInWithEmailAndPassword(auth, username, password);
const user = auth.currentUser;
const token = await user.getIdToken();
localStorage.setItem('token', token);
return Promise.resolve();
} catch (error) {
return Promise.reject(new Error(error.message));
}
},
logout: async () => {
try {
const auth = getAuth();
await signOut(auth);
localStorage.removeItem('token');
return Promise.resolve();
} catch (error) {
return Promise.reject(new Error(error.message));
}
},
checkAuth: async () => {
const token = localStorage.getItem('token');
if (token) {
return Promise.resolve();
}
return Promise.reject();
},
checkError: async (error) => {
if (error?.code === 'auth/user-not-found') {
return Promise.reject(new Error('User not found'));
}
return Promise.resolve();
},
getPermissions: async () => {
return Promise.resolve();
},
getIdentity: async () => {
const auth = getAuth();
const user = auth.currentUser;
if (!user) {
return Promise.reject();
}
const token = await user.getIdToken();
return Promise.resolve({
id: user.uid,
fullName: user.displayName,
avatar: user.photoURL,
token: token,
});
},
};
export default authProvider; No, I don't need react-admin-firebase now because I'm using Firebase Realtime Database, not Firestore. Note, I had to call get import { getAuth } from "firebase/auth";
export default (
firebaseConfig,
settings = { context: "", imagekey: "images", filekey: "files" }
) => {
const {
callbacks: { getListFormatDataCallback },
} = settings;
const firebaseApp = initializeApp(firebaseConfig);
// getAuth() must be called here in order to pick up any previous Firebase
// authentication from session cookies.
getAuth();
const database = getDatabase(firebaseApp);
const firebaseRTClient = {
create: async (source, params) => { |
Hi guys, Same error here, I am not able to pass the "app" option to the FirebaseDataProvider function because initializing in firebase v9 way. Does anybody have found a workaround ? |
When using this library one is forced to use the firebase 9 compat mode (which will be removed in one of the next versions, see https://firebase.google.com/docs/web/modular-upgrade) because
react-admin-firebase
seems not to support the modular type. Running this example:logs the following to the console:
which makes sense, because the firebase 9 way of doing it would be
getFirestore(app)
.A workaround would be to let
react-admin-firebase
create the app instance, but:Did I miss something?
The text was updated successfully, but these errors were encountered: