Firebase Tutorial: Getting Started

I need to fetch image from firebase to table view ,Anyone pls give me the ideas?

thank in advance

I’ve removed all of my users but the app still finds a user and transitions to the grocery list.

so, in the login view did load i’m looking at this:

FIRAuth.auth()!.addStateDidChangeListener() { auth, user in
  if user != nil {
    self.performSegue(withIdentifier: self.loginToList, sender: nil)
  }
}

it finds a user here even though i don’t have any. essentially i can’t get to a point where the app is at the login screen.

user prints out:
▿ Optional

any idea why this is occurring?

thanks,
josh

tutorial is fantastic, maybe the most informative
but i have one problem: when i try to create authentication and in Xcode in capabilities of project choose KeyChain Sharing, i get a message: Failed to create provisioning profile
by the way i run my app on simulator. is it important in creating authentication???
Can someone help me please?)

Great tutorial ! Thank you :slight_smile:

Great tutorial. I went ahead and implemented the sign-out method in OnlineUsersTableViewController, but the database of online users doesn’t get updated. Here’s the code (couldn’t be any simpler):

@IBAction func signoutButtonPressed(_ sender: AnyObject) {
try? FIRAuth.auth()!.signOut()
dismiss(animated: true, completion: nil)
}

Am I missing something or is this a bug in Firebase? Thanks!

Hi, good tutorial, it’s got me excited about Firebase. However the authorization is not working. So if I make a sign up it does not create a user in my firebase auth dashboard and if I manually create a user in Firebase and try to login it will not. However I see no error messages.
I am using xcode 8.1 and Swift 3
Many thanks for any help with solving this, I see some other people have the same issue

Hi I found a solution to my error. Sometime the Googleservice-info.plist is downloaded from Firebase without an API_KEY. This prevents the AUTH parts of this tutorial from working. The easy fix for it is just to download the Google info.plist again :slight_smile:

Great tutorial. THX.

Hey, is it possible to post a link to the old tutorial written in objective-c?

Great Tutorial, but there is something wrong, not working. Where you have the code for deleting a row from the table data from Firebease, it’s right for tableview, but not for Firebase:

if editingStyle == .delete {
let groceryItem = items[indexPath.row]
groceryItem.ref?.removeValue()  }

This works for tableview, but data still goes on Firebase. And the last line shows an error just before run:
"Value of type GroceryItem has no member ‘ref’

How to delete the data here also from Firebase?

Thank you.

I love this tutorial!

I am looking to only load the information submitted by the current user.

I know that I am able to get the value of the current user from Firebase, but I am not able to change the ref path to dynamically include the current uid. I keep getting an error that nil is found while unwrapping an optional. This is odd because I am able to print the same value to the console just fine.

Any thoughts, anyone?

Hi guys,
I have been trying to solve the mystery behind SigningOut a user and this is what I cam out with , The following IBAction for SingOut user look like:

@IBAction func signoutButtonPressed(_ sender: AnyObject) {
//try! FIRAuth.auth()!.signOut()

FIRAuth.auth()!.addStateDidChangeListener { auth, user in
  guard let user = user else { return }
  self.user = User(authData: user)
  
  // 1
  let currentUserRef = self.usersRef.child(self.user.uid)
  // 2
  currentUserRef.setValue(self.user.email)
  // 3
  currentUserRef.removeValue()
}
dismiss(animated: true, completion: nil)

}

Basically , " currentUserRef.removeValue()" is the code that removes the user from the list of Online users in Firebase Database, and it is working perfectly.

I ran into the exact same problem, but downloading the Googleservice-info.plist file and replacing the first one didn’t fix it for me. Instead, I had to literally cut the API key and then paste it back in. Something tells me there were hidden characters in the downloaded file which I fixed by my edit. Go figured.

Anyway, thanks for the lead. I was able to resolve my issue by reading your comment.

Cheers!

Hi ad

I tried this but get the error (at self.user)
Value of type ‘OnlineUsersTableViewController’ has no member ‘user’

Missing some declaration?

Adding
var user: User!
solved my problem :slight_smile:

Is there anyway to do an animated deletion. when you swipe left?

I have implemented the function exactly as you have described but it is not working:

@IBAction func signoutButtonPressed(_ sender: AnyObject) {

try! FIRAuth.auth()!.signOut() 

FIRAuth.auth()!.addStateDidChangeListener()
  { (auth, user) in
    guard let user = user else {return}
    self.user = User(authData: user)
    
    let currentUserRef = self.usersRef.child(self.user.uid)
    currentUserRef.setValue(self.user.email)
    currentUserRef.removeValue()
}

dismiss(animated: true, completion: nil)

}

This does not modify online users in the realtime database. I can sign in with a different user and that will increase the number of users but nothing ever signs out.

When I build and run the app from Xcode, the user WILL sign out when I STOP the process from Xcode, but when I open the app in the simulator later, it will not sign the user out.

I have also noticed that if I hard close the app from springboard it will then sign the user out, but the important thing is that

try! FIRAuth.auth()!.signout()

does not function as it is supposed to for some reason. I have also read through StackExchange tickets and checked other tutorials to no avail.

Anyone else encountering this issue?

I resolved added a property to the OnlineUsersTableViewController class:

var user: User!

then inside ViewDidLoad, at the end I added this observer:

FIRAuth.auth()!.addStateDidChangeListener { auth, user in
    if let _user = user {
        self.user = User(authData: _user)
    } else {
        let userRef = self.usersRef.child(self.user.uid)
        userRef.removeValue()
    }
}

Then inside signoutButtonPressed method:

do {
    try FIRAuth.auth()?.signOut()
    dismiss(animated: true, completion: nil)
} catch let error as NSError {
    print(error.localizedDescription)
}

Yes, but you have to move:
let userRef = self.usersRef.child(self.user.uid) userRef.removeValue()
inside try statement or you’ll get a permission denied error on Firebase. addStateDidChangeListener gets called after FIRAuth.auth()?.signOut(), then you are unauthenticated
You have to set permission rules to authenticated on Firebase

1 Like

Ran into an unexpected problem with createUser(
Firebase will send an error on the completion handler if the password doesn’t conform to some basic expectations. I was typing in one with just 5 characters - FB needs six.