External database for users?

I’ve built an app using Bubble.io for the frontend and SQL for the backend, handling everything, including authentication, through API calls. After sending the API call for login, I need to redirect the user to another page. Since I’m not using Bubble’s native authentication system (like ‘Signup’ or ‘Current User’), how can I securely store and manage the authentication token in Bubble and maintain the logged-in state across pages? What is the best approach to handle this within Bubble, given that I can’t use its primary actions for user authentication?

How long would you like user sessions to last?

At least a few hours, but it would be ideal to stay logged in for a week without being logged out :slight_smile:

If you’re happy to have user sessions last less than 3 days, then it’s much simpler. You can use Bubble’s Temporary User functionality. Essentially, even if a user is not logged in or signed up, Bubble creates a User entry where changes can persist even if the page is closed, refreshed or a page change happens.

Read more about Temporary Users on the Bubble Manual

You can leverage this simply by creating a ‘authToken’ field on the default User datatable, and using the ‘Make change to current user’ action to save the authtoken on the user (even though the user is not logged in - changes will persist thanks to temporary users)

Temp users will not be visible on the Data Tab, but they technically exist in the database, but they only last for 3 days. After that, the temp user and all data associated to them will be deleted.

If you want user session to last more than 3 days, you’ll have to create a system to SignUp the user on the Bubble database in parallel to the external DB. This is more complex to do properly, as you also have to manage account recovery and all stuff relevant to Auth. I don’t think there is a way around it without using Bubble’s Auth actions.

Thanks a lot for the thorough and clear response!

It’s been really helpful for me :slight_smile: