How do I keep my user logged in when they close my app?

Sorry if this is obvious, I couldn’t find a clear answer in the docs/forums.

At the moment, whenever I leave my app, I have to log in again when I return. I just want the user to authenticate the first time they open the app and then leave them logged in forever, as you’d expect for any app (eg. Facebook, Instagram etc).

What’s the best practice way to do this? All I could think of was turning authentication off and triggering my login screen if the authToken app variable was empty from the main landing page of my app.

2 Likes

Hi Bryony, to persist the login session, you use client-side storage for storing the authentication token and check for that token when the app opens – if it’s found, you can login the user and dismiss the initial view.

I answered a similar question some weeks ago in this thread. This tutorial also has a flow diagram and more instructions that I’ve found to explain the login flows well on a general level, even if you’re not using Bubble.

1 Like

Thank you so much for the speedy response!

Question, is this testable via the preview app? Even without the PersistedUser, my session stays valid in AppGyver Preview unless I force close the app and relaunch it, so I don’t know if I am able to emulate ‘real’ behaviour without a full build and deploy out to TestFlight?

I’ve found the preview App does store client data. The way I test that client data has been stored is using an Alert flow control to display the value of that data.

1 Like

I finally got it working, yep. I had to use the Storage functions from the market though, and it took a bit of fiddling, but hopefully it’s all done and dusted and no issues arise in my build!

2 Likes

can you please explain the process it’ll be a great help!

Hi! Did you check out the thread Mari linked above? There’s an extensive explanation there :slight_smile: