Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 987b12c

Browse files
firebase user provider data? #196
1 parent dd6386a commit 987b12c

File tree

1 file changed

+47
-14
lines changed

1 file changed

+47
-14
lines changed

docs/AUTHENTICATION.md

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ You can sign in a user either
1313

1414
Each of these login mechanisms need to be enabled in your Firebase console at the 'Login & Auth' tab.
1515

16+
## What's returned when logging in?
17+
All login functions below, as well as `getCurrentUser` return a 'User' object with these properties:
18+
19+
|param|optional|description
20+
|---|---|---
21+
|`uid`|no|The Firebase User ID
22+
|`email`|yes|Not all providers require an email address
23+
|`emailVerified`|no|You can send an email with a verification link which this refers to
24+
|`name`|yes|The name stored at the provider
25+
|`anonymous`|no|Whether or not the user logged in anonymously
26+
|`profileImageURL`|yes|A string containing a link to a user image on the web
27+
|`refreshToken`|yes|iOS only
28+
|`providers`|no|An array of {id: value} objects, where value can be 'facebook.com', etc
29+
30+
1631
## Functions
1732

1833
### Listening to auth state changes
@@ -57,6 +72,29 @@ If - for some reason - you want more control over the listener you can use these
5772
firebase.hasAuthStateListener(listener);
5873
```
5974

75+
### Get Current User
76+
Once the user is logged in you can retrieve the currently logged in user.
77+
78+
##### JavaScript
79+
```js
80+
firebase.getCurrentUser().then(
81+
function (result) {
82+
console.log(JSON.stringify(result));
83+
},
84+
function (errorMessage) {
85+
console.log(errorMessage);
86+
}
87+
);
88+
```
89+
90+
##### TypeScript
91+
```js
92+
firebase.getCurrentUser().then((user) => {
93+
alert("User uid: " + user.uid);
94+
}, (error) => {
95+
alert("Trouble in paradise: " + error);
96+
});
97+
```
6098

6199
### Anonymous login
62100
Don't forget to enable anonymous login in your firebase instance.
@@ -67,14 +105,12 @@ Don't forget to enable anonymous login in your firebase instance.
67105
type: firebase.LoginType.ANONYMOUS
68106
}).then(
69107
function (result) {
70-
// the result object has these properties ('undefined', depending on the login type):
71-
// uid, provider, expiresAtUnixEpochSeconds, profileImageURL, token
72-
JSON.stringify(result);
108+
console.log(JSON.stringify(result));
73109
},
74110
function (errorMessage) {
75111
console.log(errorMessage);
76112
}
77-
)
113+
);
78114
```
79115

80116
##### TypeScript
@@ -98,13 +134,12 @@ Don't forget to enable email-password login in your firebase instance.
98134
password: 'theirpassword'
99135
}).then(
100136
function (result) {
101-
// the result object has these properties: uid, provider, expiresAtUnixEpochSeconds, profileImageURL, token
102137
JSON.stringify(result);
103138
},
104139
function (errorMessage) {
105140
console.log(errorMessage);
106141
}
107-
)
142+
);
108143
```
109144

110145
#### Managing email-password accounts
@@ -128,7 +163,7 @@ Don't forget to enable email-password login in your firebase instance.
128163
okButtonText: "OK, got it"
129164
})
130165
}
131-
)
166+
);
132167
```
133168

134169
#### Resetting a password
@@ -143,7 +178,7 @@ Don't forget to enable email-password login in your firebase instance.
143178
function (errorMessage) {
144179
console.log(errorMessage);
145180
}
146-
)
181+
);
147182
```
148183

149184
#### Changing a password
@@ -159,7 +194,7 @@ Don't forget to enable email-password login in your firebase instance.
159194
function (errorMessage) {
160195
console.log(errorMessage);
161196
}
162-
)
197+
);
163198
```
164199

165200
### Custom login
@@ -173,13 +208,12 @@ Use this login type to authenticate against firebase using a token generated by
173208
token: token
174209
}).then(
175210
function (result) {
176-
// the result object has these properties: uid, provider, expiresAtUnixEpochSeconds, profileImageURL, token
177211
JSON.stringify(result);
178212
},
179213
function (errorMessage) {
180214
console.log(errorMessage);
181215
}
182-
)
216+
);
183217
```
184218

185219
### Facebook login
@@ -199,7 +233,7 @@ Then add the following lines to your code and check for setup instructions for y
199233
function (errorMessage) {
200234
console.log(errorMessage);
201235
}
202-
)
236+
);
203237
```
204238

205239
For a complete list of the available scope permissions, visit Facebook's documentation: https://developers.facebook.com/docs/facebook-login/permissions.
@@ -251,7 +285,7 @@ Then add the following lines to your code and check for setup instructions for y
251285
function (errorMessage) {
252286
console.log(errorMessage);
253287
}
254-
)
288+
);
255289
```
256290

257291
#### iOS
@@ -296,7 +330,6 @@ a Firebase auth token for the currently logged in user.
296330
console.log("Auth token retrieval error: " + errorMessage);
297331
}
298332
);
299-
300333
```
301334

302335
### logout

0 commit comments

Comments
 (0)