Why is my flow logic with javascript behaving different on Web and the IOS Preview app?

Dear All,

I have been stuggeling with a very basic issue, and I have not idea why this is not working.

Context:
I am testing the builtin firebase authentication in appgyver. The idea is to use custom claims in firebase to build an application that reacts differently based on the user’s roles. One use case for example is to show different content in the app based on the products that the user subscribed too.

Setup:

  1. My firebase project is created and the user already have a custom claim called “incidents” which is set to true. Using nodejs I can set and view the claims for the user.
  2. Appgyver app is created and the basic firebase authentication is enabled

Working flow logic - Web App
In the web app the following flow logic correctly gets the custom claim from the authentited user object and sets the app variable accordingly:

In the flow above the javascript function takes as input the firebase user object and get’s the custom claims:

try{

  console.debug("Getting the auth data from the token");

  var output = { };   
  var token = await inputs.firebaseUser.getIdTokenResult(true);
  if(token && token !== undefined){

    output.incidents = token.claims.incidents;
    
  }else{

    console.error("Could not get the auth data from the token: " + e);
    return [1, { error: true }];

  }
   
  return { result: output  }
 
}catch(e){ 
  console.error(e);
  return [1, { error: true }]
}

As a result of this function, the app variable is set. The binding to this variabe is visible below, where the user has the subscription for the incidents application ( shown with the toggle button set to true )

Not working - IOS Preview App
When I run this exact app via the Appgyver Preview app on IOS, the claims are not read and the app variable is not set.

My question
Is there something else I need to do to make this flow logic with javascript work also on IOS / mobile devices?

Thank you in advance for your time and support

1 Like

Hi All,

For anyone in the future having the same issue, I found the reason for this behaviour.

The Problem:
On my Global Canvas I am initializing the firebase connector. Then on my login page I am checking if the user is signed in and getting the user’s permissions. The problem here was that I was calling the Get current user (Firebase Auth) flow function before the firebase connector was fully initialized. Somehow on the web app this was allowed, and the app could proceed. The iOS app is not so forgiving and simply stops.

The Solution:
I added an app variable and set it to true in the global canvas when the initialization of the firebase connector was successful. Then on my login page I check if the initialization is completed, if not, I delay for one second and check again. Now I can see on the iOS and Web App that the code waits for the initialization to finish and then proceeds to authenticating the user.

Improvements will be to add a timeout if the initialization never finishes. Highly unlikely, but still needed to inform the user if the app cannot start due to this.

Hope this helps someone in the future. :sunglasses: :rocket:

2 Likes

It will definitely help.

I had another problem, completely different from yours, and that was also solved with the help of @Mevi , just adding a DELAY between operations.

Just implement what she suggested and the app is working.

So YES… it seems that the simple implementation of a DELAY works in several different situations.

…has anyone else had a problem resolved with DELAY? comment here…

1 Like