Asym
Asym

Reputation: 1938

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?

Upvotes: 9

Views: 9671

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

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.

Upvotes: 16

Related Questions