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

bug: getCurrentUser returns undefined user #119

Closed
kabouter opened this issue Jan 23, 2022 · 2 comments
Closed

bug: getCurrentUser returns undefined user #119

kabouter opened this issue Jan 23, 2022 · 2 comments
Assignees

Comments

@kabouter
Copy link

kabouter commented Jan 23, 2022

I'm making an Android app with framework7 and I'm stuck. I think it worked a few days ago so I'm afraid om doing something wrong. So probably not a bug. :|

Plugin version:

@robingenz/capacitor-firebase-authentication": "^0.4.0
firebase": "^9.6.3

Platform(s):

Android 11
minSdkVersion = 26
compileSdkVersion = 30
targetSdkVersion = 30

Current behavior:

The user clicks a link, my app should check if the user is logged in. but this fails and user is redirected to a login page, because the user is undefined.

EDIT: The logout is also not working. It looked like it worked, but if call firebase/auth directly I'm still logged on.

Expected behavior:

The user clicks a link, my app should check if the user is logged in. If the user isn't logged on they should be redirect to login page, otherwise the content page if the content is bought.

Related code:

import { initializeApp } from 'firebase/app';
import { FirebaseAuthentication } from '@robingenz/capacitor-firebase-authentication';
import { getAuth, browserLocalPersistence, GoogleAuthProvider, setPersistence, signInWithCredential,} from "firebase/auth";
const firebaseConfig = {
    apiKey: "xxxx",
    authDomain: "xxxx",
    projectId: "xxxx",
    storageBucket: "xxxx",
    messagingSenderId: "xxxx",
    appId: "xxxx"
  };

const FirebaseApp = initializeApp(firebaseConfig);

const getCurrentUser = async () => {
  const result = await FirebaseAuthentication.getCurrentUser();
  return result.user;
};

 $('#kopen-of-tonen').on('click', () => {
        getCurrentUser().then((user) =>{
        alert('user: '+user); //user: undefied

        alert('user: '+ getAuth().currentUser.email); //succesfully returns emailaddress
        if (user != null) {            
            if((true)){
              //load content
              request(); 
            }else {
              //buy access to content
              store.order('oefeningen');
        };
        } else {
            // No user is signed in
            app.views.main.router.navigate('/register/');
        }
      });
     })


    <div class="list links-list inset">
      <ul>
        <li><a href="#" id="kopen-of-tonen" >toegang</a></li>
      </ul>
    </div>


Other information:

When I run my app in the webbrowser I don't encounter problems(user is null if not logged on). I can also login succesfully in the webbrowser and in my android app.

I was thinking maybe it has something to with my Content-Security-Policy. This looks like this:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' 'unsafe-eval' gap: data: https://validator.fovea.cc https://ssl.gstatic.com https://blablabla.be https://*.google.com https://fonts.gstatic.com https://5e2c7.firebaseapp.com https://*.googleapis.com https://cdnjs.cloudflare.com https://unpkg.com https://cdn.firebase.com https://*.firebaseio.com  https://securetoken.googleapis.com;">

Capacitor doctor:

Latest Dependencies:

  @capacitor/cli: 3.4.0
  @capacitor/core: 3.4.0
  @capacitor/android: 3.4.0
  @capacitor/ios: 3.4.0

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/cli: 3.4.0
  @capacitor/android: 3.4.0
  @capacitor/core: 3.4.0

@robingenz robingenz self-assigned this Jan 24, 2022
@robingenz
Copy link
Owner

Hi @kabouter,
thank you for your request.
From what I see in your code, it should work.

I would have to look at your code and configuration to be able to help you further.
Please provide a Minimal, Reproducible Example (see How to create a Minimal, Reproducible Example).

I was thinking maybe it has something to with my Content-Security-Policy. This looks like this:

Does an error appear anywhere in the Developer Console or the Network tab?
Can you remove this tag for testing?

@kabouter
Copy link
Author

kabouter commented Jan 24, 2022

I stripped everything and had only auth things left. I still had the problem.
I changed from firebase web to Firebase Android.
Now it is working. User is still undefied when not logged on, but that is not a real problem. When logged on the user is no longer undefied.

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

No branches or pull requests

2 participants