Skip to content
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

RNFirebaseAuth.getToken got 2 arguments, expected 3 #42

Closed
gabrielmoreira opened this issue Apr 8, 2017 · 15 comments
Closed

RNFirebaseAuth.getToken got 2 arguments, expected 3 #42

gabrielmoreira opened this issue Apr 8, 2017 · 15 comments

Comments

@gabrielmoreira
Copy link

Sometimes this error occurs when opening the app. I did not identify the cause. I suppose it is related to the expired token of the firebase, since it usually happens after a while that I get without opening the app.

RNFirebaseAuth.getToken got 2 arguments, expected 3

invoke
BaseJavaModule.java:318

invoke
JavaModuleWrapper.java:141

...

I'm using react-native 0.42 and react-native-firebase 1.0.0-alpha12.

@Salakar
Copy link
Member

Salakar commented Apr 8, 2017

Can I see your code where you call getToken if possible please?

@gabrielmoreira
Copy link
Author

lib/firebase.js

let firebaseInitialized = false;
const firebase = new RNFirebase();
firebase.auth().onAuthStateChanged((user) => {
    firebaseInitialized = true;
});

export const getToken = (forceRefresh = false) => {
  if (firebaseInitialized) {
    if (!firebase.auth()) return Promise.resolve(null);
    let currentUser = firebase.auth().currentUser;
    if (!currentUser) return Promise.resolve(null);
    return currentUser.getToken(forceRefresh).then((token) => token);
  } else {
    return Promise.delay(100).then(() => getToken(forceRefresh));
  }
}

on my app initialization:

    getToken()

@gabrielmoreira
Copy link
Author

I am waiting for the onAuthStateChanged, to ensure that the currentUser exists, as recommended by the firebase.

https://firebase.google.com/docs/auth/web/manage-users#get_the_currently_signed-in_user

Note: currentUser might also be null because the auth object has not finished initializing. If you use an observer to keep track of the user's sign-in status, you don't need to handle this case.

@Ehesp
Copy link
Member

Ehesp commented Apr 12, 2017

@gabrielmoreira Have you had anymore luck on this? I'd suggest wiping node_modules and reinstalling. Your code AFAIK looks ok, nothing fancy going on.

@Salakar
Copy link
Member

Salakar commented May 2, 2017

Closing due to inactivity, can confirm this works currently unless this is some weird edge case. Issues like this tend to happen when yarn.lock is incorrectly installing the older versions of RNFirebase

@suwu150
Copy link

suwu150 commented Oct 22, 2021

try npm run start --reset-cache.i'm ok.

https://suwu150.blog.csdn.net/article/details/120899565

@mikehardy
Copy link
Collaborator

@suwu150 I reach for this now npx react-native-clean-project it even cleans those hard to reach places ;-)

@nikilarigela
Copy link

nikilarigela commented Feb 8, 2022

any one has the solution for this facing this issue from 2days, didn't get any solution
@Salakar please help

@mikehardy
Copy link
Collaborator

@nikilarigela make sure you have done npx react-native-clean-project or the equivalent, you have a mismatch between your javascript code and your native code, in react-native terms unless there is an error in the module (there is not) an argument count mismatch always indicates that the native code and javascript code have changed how they communicate with each other but you've got different versions of native and javascript talking to each other. It's a subtle sort of build failure basically.

@nikilarigela
Copy link

nikilarigela commented Feb 8, 2022

I have cleaned the build and cleared all cache, nothing works
RNFBMessagingModule.getToken got 4 arguments, expected 2
it throws me this

@mikehardy
Copy link
Collaborator

With apologies, I won't reply further. For the avoidance of all doubt: you have a local project problem.
Our tests app exercises tokens and does not error
My work projects do not error
You may try building a completely clean sample project even using one of two methods that get you set up to play with auth code:
https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh
https://github.com/invertase/react-native-firebase-authentication-example/

They should work, and show the modules work. Why is your project not working? It could be nearly anything, it's impossible for us to effectively provide support for the infinite variety of ways a specific project may have a problem, so we provide samples and templates instead, to produce reproductions from known-good starts https://stackoverflow.com/help/minimal-reproducible-example - if you can provide a minimal reproducible example showing the failure, we may revisit.

@nikilarigela
Copy link

Updated react native, working now
Thanks @mikehardy

@robschwitzer
Copy link

@nikilarigela what versions of firebase / rn did you settle on? facing the same issue on android device

@mikehardy
Copy link
Collaborator

Go for current + current, that is, rnfb 14.5.1, react-native 0.67.3 - the changelog here will help you https://invertase.io/blog/react-native-firebase-versioning, and https://react-native-community.github.io/upgrade-helper/ will hook you up for react-native

@meliodev
Copy link

meliodev commented Apr 6, 2022

I am using Codepush and have made some updates on firebase modules, which led to that error. Indeed Codepush doesn't deploy native code changes (It deploys only javascript code).
So, As @mikehardy mentioned, you have a mismatch between your javascript code and your native code.

In my case, I released a new apk and it started working again !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants