Kodeco Forums

Firebase Tutorial: Getting Started

In this Firebase tutorial, you'll learn Firebase fundamentals including saving data, real-time sync, authentication, user status, and offline support.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3-firebase-tutorial-getting-started
1 Like

Why didn’t you update the project to Cloud Firestore. Is more powerful and full of benefits.

Thx for the tutorial. I think you meant Swift 4.1 and not Swift 41!

It would be good if you could add how to count the items in the grocery list and display the count on the app

Thanks for letting us now, @xdeleon, I fixed the typo.

@alexz It looks like Cloud Firestore is currently still in beta. We might do a new tutorial about this in the future.

Awesome tutorial! Where in the documentation would you suggest I look to grant another user access a record and its children?

I’m a little confused by the user authentication implemented in the tutorial and the security rules for the realtime database.

If the app was in the AppStore wouldn’t all users be using the same grocery list? Any user seems able to gain access to the list by registering an email/password. How could I restrict login to say family and friends?

Or am I missing the point completely? Is this implementation of the database ‘public’ by design and not suited to simply letting a single user or a small defined group access their own data?

Actually, in your Registering Users section something should be changed. The Auth.auth().createUser(withEmail:password:) automatically signs in a user upon successful account creation. So practically you don’t need to call Auth.auth().signIn(withEmail:password:) there. And I believe this is due to change in firebase authentication design change but not at the time of writing this tutorial for the first time. More on Create a password-based account

@kmikael Could you please help with this when you get a chance? Thank you - much appreciated! :]

Normally, you would implement Auth differently. We only made everything public for simplicity in this tutorial. You can restrict access such that a user can only see their collection for example.

You can see this guide: Use conditions in Realtime Database Security Rules  |  Firebase Realtime Database

If I’m understanding correctly, you want to edit security rules. You can try here: Use conditions in Realtime Database Security Rules  |  Firebase Realtime Database

Mikael, maybe the reader would understand that you have to exit XCode before doing a ‘pod install’ but you should really say so expressly, and that one loads the .xcworkspace file thereafter.

Thanks for the concerns. This is an intermediate tutorial and we decided to assume the reader knows how to use CocoaPods. There are many online tutorials about this including the official site.

Hey @kmikael thanks a lot for a great tutorial!
May I ask you how we would Update and existing cell with Firebase? I am kinda struggling on figuring that out.
Any info is greatly appreciated,
Thanks!

@kmikael Can you please help with this when you get a chance? Thank you - much appreciated! :]

Is there a version of this which uses CloudKit/iCloud?

Hi there. Thanks for the awesome tutorial! I am struggling to understand how in LoginViewController.swift you manage to call performSegue() within viewDidLoad, before the view is totally loaded and visible? Is this something to do with Firebase?Thank you

@kmikael Do you have any feedback regarding this? Thank you - much appreciated! :]

SOLVED: For Registering Users, users are only added to Firebase when the password is minimum of 6 characters!. If you put in less than 6 characters, users will not be added to the Firebase user panel.

Hi @kmikael,

I believe the section, Registering Users, should be updated. I followed your instructions and do not see any new users being registered in my Firebase Authentication panel. I am able to add items to the list and see the effects immediately so that’s fine, but the same doesnt happen for when I try to sign up new users. Another user above, nayem, made similar mention of this as well.

And yes, I have Email/Password enabled in the Authentication > Sign-in Method panel.

Code in LoginViewController.

@IBAction func signUpDidTouch(_ sender: AnyObject) {
    let alert = UIAlertController(title: "Register",
                               message: "Register",
                               preferredStyle: .alert)
    
    let saveAction = UIAlertAction(title: "Save", style: .default) { _ in
        // 1
        let emailField = alert.textFields![0]
        let passwordField = alert.textFields![1]
        
        // 2
        Auth.auth().createUser(withEmail: emailField.text!, password: passwordField.text!) { user, error in
            if error == nil {
                // 3
                Auth.auth().signIn(withEmail: self.textFieldLoginEmail.text!,
                                 password: self.textFieldLoginPassword.text!)
            }
        }
    }
.....