3

Hello i have just started playing with firebase. My problem here is that i want to only print the current users email. Not everything that comes with it....

This is what the print block looks like:

[email: test@gmail.com, isTemporaryPassword: 0, profileImageURL: https://secure.gravatar.com/avatar/1aedb8d9dc4751e229a335e371db8058?d=retro]
Optional(Secret code)

And this is how i print it:

print(CURRENT_USER.authData.providerData)

This is where i save the user:

var CURRENT_USER: Firebase
{
    let userID = NSUserDefaults.standardUserDefaults().valueForKey("uid") as! String

    let currentUser = Firebase(url: "\(FIREBASE_REF)").childByAppendingPath("users").childByAppendingPath(userID)

    return currentUser
}

code https://gyazo.com/20b2dcd0ddd7c7f8c61858ca1d653e3b

firebase users https://gyazo.com/ce4516ef9a6ebf6963a9a1a43807158d

2 Answers2

5

For swift 4

let userEmail = Auth.auth().currentUser?.email
3

Try this:

print(CURRENT_USER.authData.providerData["email"] as! String)

I have tried and it worked for me. It will print the current user email.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Twitter khuong291
  • 11,328
  • 15
  • 80
  • 116