Ionic React + Capacitor: useAuth0 works on web, but native build returns no user or isAuthenticated

Hi everyone ,

I’ve been testing the official Auth0 React quickstart for Ionic + Capacitor. After two days of testing, here’s what I found:

  1. Web: Demo app works fine with minor setup adjustments. isAuthenticated and user update as expected.

  2. Mobile HTTPS/WebView: Works in mobile browser or WebView—but this is just the web app running on mobile, not a true native app.

  3. Native build: Auth0 completely fails:

    • user is undefined (I tried to display user.name and user.email, but nothing shows up.

    • isAuthenticated is always false

    • Logout/login works, but useAuth0 hook never provides values

Question:

Has anyone successfully used the Auth0 React quickstart with Ionic & Capacitor in a native app? How do you ensure isAuthenticated and user Update correctly on native builds?

Any guidance or examples would be greatly appreciated!


Welcome back to the Auth0 Community!

I will be taking a look at the issue that you are having and will come back with an update on both of your posts as soon as possible. Thank you for your patience!

Kind Regards,
Nik

Hi again @extrat30

Could you creating a hook in order to update the the token in the background at specific intervals as stated in this StackOverflow thread?

Also, by any chance do you have your App component wrapped in inside the index.tsx or other index files?

Kind Regards,
Nik

Here is my observation after trying for the past two days:

  1. Your demo app for Ionic + Capacitor (React) works fine on the web. I did encounter some minor errors that needed setup, but overall it works.

  2. If I serve the app with HTTPS on my mobile, it runs fine in the mobile browser or in a WebView. However, this is just a projection of the web app running on mobile—it’s not the real native app.

  3. When I build the app for a native environment, Auth0 completely fails. I don’t get any user data, and isAuthenticated is always false. I can log out and log in perfectly, but the useAuth0 hook does not provide any of these values.

Initially, I thought the issue was that useEffect was not triggering, but after testing, it turns out the main issue is that in the native app, I simply don’t get the Auth0 values at all. I’m not sure why it’s failing or what the correct approach should be for Auth0 in a fully native environment.

I think you can check that out too. Just run your example app and build that native app you will find that issue too


Whenever you build the app in a native environment, just to double check, you mean that you ran it using a emulator? If yes, have you tried running the application on an actual mobile device to see if there are any changes between these two environments?

I will investigate further regarding your findings to provide further updates/feedback.

Kind Regards,
Nik