Use a formula to set raw data from storage into an app/page variable

Hi guys,

Does anyone know this? I would like to make an authentication system working and I have been using this tutorial for it:

Though, the part of saving and using data from people logging in (persisteduser part), is something that I have not yet learned to pull off.

Could someone help me on this?

Hi Jordan, here’s one way to implement a persistent login session:

  1. Setup: Create a client-side data resource for the user details, let’s call it PersistedUser in this example. It will most likely be an object with fields for the required information (user ID and session token or similar).
  2. Saving user: When the user logs in, use the Create record flow function to save the user’s details into a new PersistedUser record. You can give the record any ID, just remember to use the same ID later on.
  3. Fetching logged in user: On the Global Canvas, use the Get record flow function after app launch to see if a PersistedUser record with your chosen ID exists. If yes, you can dismiss your app’s initial login view and use the information in the record to authenticate the user.
  4. Deleting user: To implement sign out, use the Delete record flow function to remove the PersistedUser record with your chosen ID. You can return to your initial view using the Return to initial view flow function from the Marketplace.

Hope this helps!

1 Like

Hi Mari,

Thanks for the response, really appreciate it!

I am just thinking about how I can use this in combination with the tutorial I mentioned in the initial message (where there is also AuthUser & currentUser).
Do you have any ideas for this?

Hi, could you still elaborate a bit what part of the tutorial exactly you’re having trouble with?

To answer the question in the name of the thread – you can use the output from the Create record node to set the value of the authUser app variable (flow visible here in the tutorial).

Sorry for overlooking that in my previous reply!

Hi Mari,

Thanks for your response!

I am having trouble at

No worries, really happy for the support I get here

Oh, looks like they left the description out of that part :smile:

In that step the tutorial uses the Set item to storage flow function (found in Flow function market). Using the Set/Get/Delete item from storage flow functions is an alternative way to achieve what I described in my first message (using Get/Update/Delete record), and in case you use them you don’t need to create a client-side data resource, since the record stores whatever data you give to it.

So in the Set item to storage node, the local storage variable is given an Item key (that is used to retrieve the persisted user details once the app opens again or to delete them if the user wants to log out). Data to store is bound to the authUser app variable that contains the user details, which it gets from the output of the previous Login / Create Record node.

@Mari Can you please explain “use the information in the record to authenticate the user.” When I use this information, I get the 401 error with message “missing or invalid authentication”
I assume this is because the authentication has expire when the 60 mins are over.
Do you also face this error?

Thank You

Also in the step3, the token expires after 1 hours, so even when the PersistentUser exist I will have to make a call to server to update the token. Right ? @Mari

Hi @DG_L, you’re right, you will have to make a request to your backend in case the token has expired to refresh it, and need to save any information needed for this request in local storage so it’s available to you. On Global Canvas, you can add a check as the first thing when the app launches to see if the token has expired, and if so, refresh it and then continue with normal execution of the app.

@Mari Does the same 1 hour limit applies if I use Firebase Connector?

Hi can you please share the flow in the Global Canvas for this functionality?

Hi @Kaushik_Bhattacharya, a similar flow for fetching a “settings” record is explained in this power-up starting at 1:00

1 Like