Skip to content

Commit 0f9f1e9

Browse files
SUPERCILEXsamtstern
authored andcommitted
Document determining if a user is new or not (#1015)
1 parent 7d77983 commit 0f9f1e9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

auth/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,22 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
353353

354354
Twitter also returns an AuthToken Secret which can be accessed with `idpResponse.getIdpSecret()`.
355355

356+
##### User metadata
357+
358+
While `IdpResponse` provides user information about a specific sign-in instance, it is usually
359+
preferable to find the user name, email, and other metadata directly from the currently signed-in
360+
`FirebaseUser` instance (`auth.getCurrentUser()`). For example, you could determine if the user
361+
who just signed in is an existing or new one by comparing the user's creation and last sign-in time:
362+
363+
```java
364+
FirebaseUserMetadata metadata = auth.getCurrentUser().getMetadata();
365+
if (metadata.getCreationTimestamp() == metadata.getLastSignInTimestamp()) {
366+
// The user is new, show them a fancy intro screen!
367+
} else {
368+
// This is an existing user, show them a welcome back screen.
369+
}
370+
```
371+
356372
### Sign out
357373

358374
With the integrations provided by AuthUI, signing out a user is a multi-stage process:

0 commit comments

Comments
 (0)