Offline Simple Login

678 views
Skip to first unread message

Thomas

unread,
May 15, 2014, 1:44:40 AM5/15/14
to fireba...@googlegroups.com
I have Simple Login working, and offline persistence working in iOS, and it is working well. In fact, my client thinks I'm a hero because I chose Firebase. Thanks, guys!

However, I'm about to move onto security rules, and here's where I have a problem. The app I'm developing (using Titanium) has to operate offline a lot of the time. firebaseSimpleLoginWithURL() doesn't even call its callback when created offline, so I've worked around it by storing a password hash in the data to allow login when the app restarts offline. The problem I see is that the security rules need to know the auth status.

So here are my questions:

- are security rules even applied when offline and using local persistence?

- if so, how do I tell Firebase Simple Login that the current user is actually authorised?

BTW, great job on Firebase Hosting. It is a great way to serve a Titanium MobileWeb app, especially now that Titanium 3.x is natively compatible with the Javascript Firebase API. And so easy to deploy to!

Regards
Thomas

Michael Lehenbauer

unread,
May 15, 2014, 5:11:15 PM5/15/14
to fireba...@googlegroups.com
Hey Thomas,

Glad things are going well with Titanium and Firebase.

Security rules are not applied by the client while offline.  In fact, they're not applied by the client while online either; they're only enforced by the server.  The client will always act as if your writes and observers succeed and then once the server enforces security, it'll react appropriately (i.e. by reverting your write or canceling your observer).

So in general, you don't need to worry about auth and security rules while offline.  The big thing you do need to worry about though is when Firebase manages to reconnect to the server, it's going to send your current auth credential (whatever you last authenticated with) to the server and then send all of the outstanding writes that you did while offline.  If that auth credential is no longer valid, your writes performed while offline will fail.

The easiest approach for dealing with that is to make sure your tokens have very large expirations, and refresh them frequently so the user would have to be offline for an excessively long period of time in order for the token to expire.

Hope this helps,
-Michael


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas

unread,
May 15, 2014, 5:24:49 PM5/15/14
to fireba...@googlegroups.com
Michael,

thanks for the info-- that makes sense. I'll make sure the expirations are long.

BTW, it took around 18 hours between the time I posted my question on the groups.google web site and it appeared in the web site and my email. I thought I'd have to post again.

Regards
Thomas

Vince Stross

unread,
Jul 28, 2014, 9:24:50 PM7/28/14
to fireba...@googlegroups.com
Hi Thomas,

Sorry for waking-up an old thread, but you mentioned that "Titanium 3.x is natively compatible with the Javascript Firebase API" and I can't find any evidence for this. Are you using a WebView? I'm near completion of a Titanium iOS native module that wraps the Firebase iOS library. If you've discovered a way to include the vanilla firebase.js without using a WebView hack I would love to know more!

V

Thomas

unread,
Jul 28, 2014, 9:58:28 PM7/28/14
to fireba...@googlegroups.com
Vince,

I was talking about MobileWeb. It's an ugly hack, but it works. Download the Firebase script to your project, then edit it to add module.exports = Firebase; at the bottom then require it as a module. It works, but requires maintenance when new Firebase releases come out.

The bad news is that I developed a Titanium native iOS module some time ago, and it works-- mostly. The problem is that as Firebase usage increases, and the user interface complexity increases, especially on slower devices, Titanium's single-threaded Javascript environment intermittently hangs. The user interface is stuck, the debugger says nothing is happening, but setTimeout() calls are not made, in fact nothing on the Javascript stack gets called. Other iOS threads such as the Firebase module are all happily running and logging activity, but the Titanium JS thread is stuck. Only quitting and relaunching the app fixes it.

I haven't done enough testing to see if the same problem occurs in MobileWeb or Android.

To get my project finished, I'm in the process of replacing the worst offending Titanium window with a native iOS module, with no Titanium involvement other than loading the window. I'm really not impressed with Titanium's robustness, nor the Titanium developer community who were unable to offer any suggestions on how to track down the hang.

My advice to newcomers is: don't mix heavy Titanium user interface with heavy Firebase data interaction.

Regards
Thomas

Vince Stross

unread,
Jul 28, 2014, 10:27:16 PM7/28/14
to fireba...@googlegroups.com
Hey Thomas,

I recently submitted my native iOS module to the Appcelerator marketplace, and it's waiting approval. If I send it to you would you be willing to drop it into your project and see if your experience is any different using my version? I've had very good results thus far, but it sounds like whatever you're working on would be a really good stress test scenario. I'm planning on charging a small amount for the module (been working on it for months), but for your assistance you would earn a lifetime free pass... which may or may not turn out to have any value! :) I've tested it on a few small projects and it's been working flawlessly, but I have no idea if it will work in an app with a bunch of UI candy.

Let me know if you're willing to give it a beta test and I'll send you a private link to the packaged module file. It's literally a plug-n-play. Check out this link for the "documentation" ... which is basically just a quick example of the subtle difference between my module and the native Firebase, and a link to the official Firebase docs. The only real difference is how the reference is created, then everything... literally everything else is the same.

I developed this to satisfy the requirements of a project I'm working on, and so far it's working very well. However, it's a private Enterprise app, not anything that will ever be on the App Store.

I'm almost finished with the sync adapter, and I can plug-in the SimpleLogin library without a problem, but I'm waiting until I know the foundational "Firebase" library is working.

V

Thomas

unread,
Jul 29, 2014, 12:10:55 AM7/29/14
to fireba...@googlegroups.com
Vince,

It looks good. I'm willing to give it a try. Please send details to info at ivfr dot net.

I also had a Backbone sync adaptor, but eventually bypassed it while trying to track down the cause of the freezes.

I'd also be interested to know how you configured module.xcconfig. I could never get it to include all the right libraries in the Titanium project that used the module.

Regards
Thomas

On Tuesday, 29 July 2014 12:27:16 UTC+10, Vince Stross wrote:
Hey Thomas,
Reply all
Reply to author
Forward
0 new messages