-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[🐛] Other Platforms - [Web] [Auth] Methods are unsupported or not existing #7921
Comments
Another issue (would create later): the need of polyfill setimmediate otherwise error is thrown:
|
Hey @younes0 , did you find a solution for that? |
@shilo-klydo using the polyfill works fine. Which problem are you reffering to ? |
The setImmediate. sorry for the ignorance, what do you mean by polyfill? |
@shilo-klydo add this polyfill package https://github.com/yuzujs/setImmediate and import it at the top of your |
I am also having this problem (version: 20.3.0), happens when calling Any solutions? Also for setImmediate, same error happens to me but only when building with
|
I managed to make auth working by commenting these lines in // Returns a cached Firestore instance.
function getCachedAuthInstance(appName) {
if (!instances[appName]) {
// if (!isMemoryStorage()) {
// // Warn auth persistence is is disabled unless Async Storage implementation is provided.
// // eslint-disable-next-line no-console
// console.warn(
// ```
// Firebase Auth persistence is disabled. To enable persistence, provide an Async Storage implementation.
// For example, to use React Native Async Storage:
// import AsyncStorage from '@react-native-async-storage/async-storage';
// // Before initializing Firebase set the Async Storage implementation
// // that will be used to persist user sessions.
// firebase.setReactNativeAsyncStorage(AsyncStorage);
// // Then initialize Firebase as normal.
// await firebase.initializeApp({ ... });
// ```,
// );
// }
instances[appName] = initializeAuth(getApp(appName), {
// persistence: getReactNativePersistence(
// getReactNativeAsyncStorageInternal(),
// ),
});
}
return instances[appName];
} Of course, this is not a even a workaround since you lose auth persistence. |
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions. |
not stale |
I am also having the same issue when I try to run on web. |
@younes0 Are you using expo ? Is your app also using Native ? What does your setup look like ? Does anyone know if calling |
Has anyone been able to use this library on web ? Can someone provide any examples ? |
I use it on web, but before the "other" platform support, via shims that alias the packages between react-native-firebase and firebase-js-sdk, similar to what was implemented here but an older style. There is a demonstration of same here, you can see the shim definitions that do the aliasing for webpack: On the web, you run initializeApp: On other platforms you do not, because it is done at a very very early stage of app initialization in native code You can think of it this way: one of the primary reasons to run firebase natively (vs just using firebase-js-sdk) is for crashlytics to be usable, and catch all native crashes including those at startup before the javascript engine is running. Additionally to start logging performance timers and perhaps startup analytics. Those all happen natively, prior to javascript being available, so the app must already be initialized natively correct? It is, from the google services json/plist files whose information is built into the app at boot time and used by the native sdks |
I wonder the support for "Other Platforms" works. I tried this with Platform checks, but it looks ugly. If someone can point to where I might be able to start looking into to fix this, I would even love to contribute to this. I was browsing package code today, but it being split into individual packages makes it slightly harder. if someone has some context, I would love if I can be given context and help speed this up. |
I'm not aware of any other way to do it, given what I wrote above about the timing of initialization. Web must initialize delayed once you have javascript available, native must initialize very very early before javascript is available. Developers want features (boot time crash detection, performance etc), developer must accept realistic constraints 🤷 I haven't used the new "other" platform style myself yet and I'm not sure many have but the e2e test apps here may provide a reasonable baseline for understanding it - specifically the macos one as it is integrated using "other" if I understand correctly |
@Salakar If I remember correctly, it's you who implemented this. Do you have any insights on this. Sorry for tagging you directly |
I've created unified interfaces for Firebase in web and React Native:
// auth.adapter.ts
// =====================================================
import { Platform } from "react-native";
import auth, { FirebaseAuthTypes } from "@react-native-firebase/auth";
import {
Auth as WebAuth,
UserCredential as WebUserCredential,
getAuth as getWebAuth,
signInWithCustomToken as webSignInWithCustomToken,
} from "@firebase/auth";
// types
// ---------------------------------------------------------------------------------
type AuthInstance = WebAuth | FirebaseAuthTypes.Module;
type UserCredential = WebUserCredential | FirebaseAuthTypes.UserCredential;
// methods
// ---------------------------------------------------------------------------------
export const getAuth = (): AuthInstance =>
Platform.OS === "web" ? getWebAuth() : auth();
export const signInWithCustomToken = (token: string): Promise<UserCredential> =>
Platform.OS === "web"
? webSignInWithCustomToken(getWebAuth(), token)
: auth().signInWithCustomToken(token);
// database.adapter.ts
// =====================================================
import { Platform } from "react-native";
import {
DataSnapshot as WebDataSnapshot,
Database as WebDatabase,
DatabaseReference as WebDatabaseReference,
getDatabase as webGetDatabase,
onValue as webOnValue,
ref as webRef,
set as webSet,
} from "@firebase/database";
import {
FirebaseDatabaseTypes as NativeTypes,
getDatabase as nativeGetDatabase,
onValue as nativeOnValue,
ref as nativeRef,
set as nativeSet,
} from "@react-native-firebase/database";
// types
// ---------------------------------------------------------------------------------
export type DatabaseType = WebDatabase | NativeTypes.Module;
export type DatabaseReferenceType =
| WebDatabaseReference
| NativeTypes.Reference;
export type DataSnapshotType = WebDataSnapshot | NativeTypes.DataSnapshot;
export type UnsubscribeType = () => void;
// methods
// ---------------------------------------------------------------------------------
export const getDatabase = (): DatabaseType =>
Platform.OS === "web" ? webGetDatabase() : nativeGetDatabase();
export const ref = (db: DatabaseType, path: string): DatabaseReferenceType =>
Platform.OS === "web"
? webRef(db as WebDatabase, path)
: nativeRef(db as NativeTypes.Module, path);
export const onValue = (
reference: DatabaseReferenceType,
callback: (snapshot: DataSnapshotType) => void,
): UnsubscribeType =>
Platform.OS === "web"
? webOnValue(
reference as WebDatabaseReference,
callback as (snapshot: WebDataSnapshot) => void,
)
: nativeOnValue(
reference as NativeTypes.Reference,
callback as (snapshot: NativeTypes.DataSnapshot) => void,
);
export const set = (
reference: DatabaseReferenceType,
value: any,
): Promise<void> =>
Platform.OS === "web"
? webSet(reference as WebDatabaseReference, value)
: nativeSet(reference as NativeTypes.Reference, value);
// FirebaseProviders.tsx
// =====================================================
import { PropsWithChildren } from "react";
const FirebaseProviders = ({ children }: PropsWithChildren) => children;
export default FirebaseProviders;
// FirebaseProviders.web.tsx
// =====================================================
import { PropsWithChildren } from "react";
import { getApp, getApps, initializeApp } from "@firebase/app";
import { initializeAuth } from "@firebase/auth";
import { FirebaseAppProvider, AuthProvider } from "reactfire";
import { getMmkvPersistence } from "@/modules/firebase/utils/auth-mmkv-persistence";
const firebaseConfig = {
apiKey: process.env.EXPO_PUBLIC_FIREBASE_API_KEY,
appId: process.env.EXPO_PUBLIC_FIREBASE_APP_ID,
authDomain: process.env.EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.EXPO_PUBLIC_FIREBASE_DATABASE_URL,
messagingSenderId: process.env.EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
projectId: process.env.EXPO_PUBLIC_FIREBASE_PROJECT_ID,
};
export const firebaseApp = getApps().length
? getApp()
: initializeApp(firebaseConfig);
export const fireBaseAuth = initializeAuth(firebaseApp, {
persistence: getMmkvPersistence(), // required: persist auth token in mmkv
});
const FirebaseProviders = ({ children }: PropsWithChildren) => (
<FirebaseAppProvider firebaseConfig={firebaseConfig}>
<AuthProvider sdk={fireBaseAuth}>{children}</AuthProvider>
</FirebaseAppProvider>
);
export default FirebaseProviders; Code shared under MIT license. |
Thank you so much @younes0, I did something very similar too. |
Is there an existing issue for this?
Please confirm you are aware of the 'Other' platform limitations.
Please confirm, this issue is NOT for Android or iOS?
Please describe your issue here.
When using auth module on web, usage of these methods
Located in
auth\lib\index.js
throw exceptions :NativeFirebaseError: [auth/unsupported] This operation is not supported in this environment
forNativeFirebaseError: [auth/unknown] "" is not a function
forFirebase app, firestore & database are initiated without any issues.
Additional context and comments
No response
The text was updated successfully, but these errors were encountered: