Skip to content
This repository has been archived by the owner. It is now read-only.

bug: Auth instance doesn't get authenticated #92

Closed
mesqueeb opened this issue Oct 6, 2021 · 5 comments
Closed

bug: Auth instance doesn't get authenticated #92

mesqueeb opened this issue Oct 6, 2021 · 5 comments
Assignees
Labels
platform: web Web platform

Comments

@mesqueeb
Copy link
Contributor

mesqueeb commented Oct 6, 2021

On Capacitor 3.0, using Firebase v9 with modular syntax I have the issue that my auth instance doesn't get authenticated.

This is the way I'm instantiating my firebaseApp and auth:

/**
 * @param {import('firebase/app').FirebaseApp} _firebaseApp
 * @returns {import('firebase/auth').Auth}
 */
function createFirebaseAuth(_firebaseApp) {
  const auth =
    platform === 'web'
      ? getAuth(_firebaseApp)
      : initializeAuth(_firebaseApp, { persistence: indexedDBLocalPersistence })
  useDeviceLanguage(auth)
  return auth
}

const firebaseApp =  initializeApp(config)
const auth = createFirebaseAuth(firebaseApp)

I need to use initializeAuth on capacitor iOS/android, because otherwise the app doesn't launch properly. (see the reason for that here).

The entire app we have uses these firebaseApp and auth instances. We need to use capacitor-firebase-authentication just to authenticate and nothing else.

I get the feeling looking at the source code that capacitor-firebase-authentication uses their own instantiated auth instance that's completely separate from ours.

I feel that especially because I can't see any way to pass our auth instance to get authenticated.

How can I best solve my issue?

Currently all the authentication methods of this library work, but just nothing happens after that and our auth instance never gets authenticated.

Best regards.

@mesqueeb
Copy link
Contributor Author

mesqueeb commented Oct 6, 2021

PS: I have this in the capacitor config:

 "FirebaseAuthentication": {
      "skipNativeAuth": true,
      "providers": [
        "apple.com",
        "google.com",
        "twitter.com"
      ]
    },

@robingenz
Copy link
Owner

Thank you for your request. You already know that I am very busy at the moment. I will take a closer look at the problem as soon as possible.

Some initial points:

Make sure to initialize the Firebase JS SDK before using the plugin.

I need to use initializeAuth on capacitor iOS/android, because otherwise the app doesn't launch properly. (see the reason for that here).

Try to use only initializeAuth. initializeAuth worked fine the last time I used it with Capacitor.

I get the feeling looking at the source code that capacitor-firebase-authentication uses their own instantiated auth instance that's completely separate from ours.

See this answer.

I feel that especially because I can't see any way to pass our auth instance to get authenticated.

It should not be necessary to pass the auth instance.

@robingenz
Copy link
Owner

Please give this dev version a try:

npm i @robingenz/capacitor-firebase-authentication@0.3.11-dev.6bac8eb.1633528448

Note: I removed the authStateChange listener.

@robingenz robingenz self-assigned this Oct 6, 2021
@robingenz robingenz added the platform: web Web platform label Oct 6, 2021
@mesqueeb
Copy link
Contributor Author

mesqueeb commented Oct 6, 2021

Dear @robingenz my issue was actually with Capacitor iOS, not the web. I use my own made functions for the web version and do not rely on your web implementation. : )

However, I found a document in your repository that I must have missed before:

https://github.com/robingenz/capacitor-firebase-authentication/blob/main/docs/firebase-js-sdk.md

This doc allowed me to implement proper auth for iOS!

One remark:

Before I kept getting

SyntaxError: Unexpected token '}'. Expected ')' to end an argument list.

But on your latest 0.3.11-dev.6bac8eb.1633528448 I don't seem to get it anymore. I'm not sure where the issue lied as it only pointed to my vendor.js minified code... 😅 But your last update seems to have helped...

Can you release it officially?

@mesqueeb mesqueeb closed this as completed Oct 6, 2021
@robingenz
Copy link
Owner

That is great!

However, I found a document in your repository that I must have missed before:

Yes, I need to make this document more visible.

But on your latest 0.3.11-dev.6bac8eb.1633528448 I don't seem to get it anymore.

That's very strange! I have removed only one listener. See this commit.
Of course I don't want to publish this, because otherwise I would remove a feature.
The problem must be another. 🤔

Can you please try again? Maybe a npm ci will help?
If the problem still occurs, please create a new issue. I will look for it then.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: web Web platform
Projects
None yet
Development

No branches or pull requests

2 participants