Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Firebase - storing data without authentication

I'm making a sample note-taking app with Firebase where users can login and create simple text notes. My Firebase data structure is as follows:

"Project-dir":{
    "Notes":{
        "UserID":{
            "NoteKey":{
                "title":"This is note title",
                "content":"This is the note content",
                "unixTime":123456789
            },
            "NoteKey":{
                "title":"This is note title",
                "content":"This is the note content",
                "unixTime":123456789
            },
        }
    }
}

It works fine with user logging in. However, I want to add "Continue without login" functionality. I generated unique User ID using push() to use instead of auth UID and stored in sharedprefs. However, how can I migrate all those notes to the user's UserID(UID) when he decides to sign in later?

like image 810
Asym Avatar asked Dec 21 '16 18:12

Asym


People also ask

Can we use Firebase database without authentication?

Any Firebase Realtime Database URL is accessible as a REST endpoint. All we need to do is append . json to the end of the URL and send a request from our favorite HTTPS client and we can access the data. It was confirmed that this Firebase Realtime Database URL is accessible without authentication.

Can I use Firebase as offline database?

By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache.

Can I use Firebase only for authentication?

You can use Firebase Authentication to allow users to sign in to your app using one or more sign-in methods, including email address and password sign-in, and federated identity providers such as Google Sign-in and Facebook Login.

How do I manually add data to Firebase?

If you open your app from Firebase dashboard, you can add data manually by clicking on the + sign.


1 Answers

For this specific use-case you'll want to use the Anonymous Authentication provider of Firebase Authentication.

It does essentially the same as you now do (it generates a random ID for the current user/device). The difference is that you can upgrade the anonymous authentication user to an identified user later, by linking their Facebook/Google/Github/Email account.

like image 187
Frank van Puffelen Avatar answered Sep 29 '22 23:09

Frank van Puffelen