Local Storage of Auth Tokens in Bubble

Not a question, but just posting this because there aren't good posts for this.

The recommendation from the Xano team in connecting to Bubble is to use the Local Storage plugin that's available on the Bubble plugin marketplace. This typically works, but in testing, I've found to not be consistently reliable. [image.png]The recommended plugin. The logo has since changed since  did his tutorial video.

Frequently, instances like this happens: [image.png]I've contacted Bubble's team multiple times and wrangled with them over multiple emails. A summary of events: 
• They claim that sometimes, the value of the authToken can't be passed on fast enough into an external API call because it's stored in a 3rd party external plugin. 
• This is despite the workflow appearing to be functional in Bubble's debugger.
• Bubble's technical support team claim that simply adding a 'Delay' using their 'Add a pause before next action' function will help solve this issue.[image.png]
• I've tried this, and while it works sometimes, have failed multiple times as well, even if I increase the 'Delay' duration.
• I've also tried to go around this by saving the authToken into Bubble's Custom States each time a page loads, to no success. [image.png]

Solution I've found:
Bubble's 'Current User' functionality essentially saves a cookie to the browser, even if the user isn't logged in by Bubble standards.[image.png]What this means is that you can save data into the 'Current User' object. By creating a field 'authToken' in my User table in Bubble, I can now use the 'Current User' functionality inbuilt into Bubble as a substitute for the Local Storage Plugin. 

I've found this to work 100% of the time (so far) - somehow being in the Current User object means it's 'fast enough' to be passed into external API calls.

Hope this saves some people time. Spent days wrangling around this.

Edit: The Current User cookie that Bubble sets expires after 3 days if the User isn't logged in with Bubble's authentication system. Just a point to note here to not use this solution if this is a dealbreaker for you. 
Connect Xano to...
8 replies