Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling firebase authentication without internet connection (Android)

I'm developing my first app using firebase. I've run into some problems with the login.

Basically, what I've got so far:

  • Users can login with their google account
  • Users can login anonymously
  • User data is stored in firebase real time database using the UID from firebase authentication as unique key

My problem

When a user uses the app for the first time, they don't have an account yet and if they have no internet connection, they won't be able to create one (at least I think so).


My question

What is the best way to handle this? Is there a possibility to get a unique key without internet connection? Should I ask the user to create a internet connection? Other possibilities?

like image 326
Ian Fako Avatar asked Feb 18 '17 21:02

Ian Fako


2 Answers

Creating a Firebase Authentication user account requires making a connection to the Google servers. Unfortunately this even applies when you use anonymous authentication.

So currently the only option (within Firebase Authentication) is to have the user connect to the internet to complete the registration.

like image 109
Frank van Puffelen Avatar answered Sep 27 '22 23:09

Frank van Puffelen


You can see if the user is authenticated offline only if he has already logged in or registered before, and then he saved the user again in the FirebaseAuth.instance.. but for every request he needs the connection.

In my case I'm using Flutter:

var user = await FirebaseAuth.instance.currentUser();

This offline log status allows you not to present a login or registration page every time the user is offline and opens your app.

like image 45
AlexPad Avatar answered Sep 27 '22 23:09

AlexPad