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.
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).
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?
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.