9

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?

1 Answer 1

16

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.

5
  • Thanks! This is what I was looking for!
    – Asym
    Dec 21, 2016 at 19:29
  • Good good. Can you help me by telling what would've made it easier for you to find this, without having to ask here? The question is totally valid, I'd just like it even better if we had the information in a spot/format that you would've before having to ask. Dec 21, 2016 at 19:31
  • Well, it's right there in documentation but I didn't think that Firebase would have this feature built-in, when it can be done (possibly?) manually.
    – Asym
    Dec 21, 2016 at 19:43
  • Darn. I was hoping to have a way to improve this. Thanks for the feedback! Dec 21, 2016 at 19:45
  • @FrankvanPuffelen - What I am unclear about: Is an anonymous authentication inherently temporary? Does the data become inaccessible once the session ends and the auth key is lost? You would assume so... It's a shame I can't supply a pre-existing GUID (from elsewhere) to make it non-temporary. Use-case: an un-authenticated Action on Google (Where users DO have a GUID supplied at all times, but full account linking is bothersome)
    – spechter
    Jul 17, 2017 at 8:15

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.