Hi Jordan, here’s one way to implement a persistent login session:
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).
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.
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.
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.
Oh, looks like they left the description out of that part
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?
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.