Filip Bellander
Filip Bellander

Reputation: 53

Firebase swift retrieve email with uid

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: [email protected], 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

Upvotes: 3

Views: 2140

Answers (2)

lets_do_coding
lets_do_coding

Reputation: 97

For swift 4

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

Upvotes: 5

Twitter khuong291
Twitter khuong291

Reputation: 11682

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.

Upvotes: 3

Related Questions