Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[Firebase Auth] added access to User metadata (#718)
Browse files Browse the repository at this point in the history
* add access to user metadata
  • Loading branch information
LucasParsy authored and kroikie committed Oct 3, 2018
1 parent df583bc commit e920cf7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/firebase_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.2

* Add access to user metadata.

## 0.6.1

* Adding support for linkWithTwitterCredential in FirebaseAuth.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ private Map<String, Object> mapFromUser(FirebaseUser user) {
providerData.add(Collections.unmodifiableMap(userInfoToMap(userInfo)));
}
Map<String, Object> userMap = userInfoToMap(user);
userMap.put("creationTimestamp", user.getMetadata().getCreationTimestamp());
userMap.put("lastSignInTimestamp", user.getMetadata().getLastSignInTimestamp());
userMap.put("isAnonymous", user.isAnonymous());
userMap.put("isEmailVerified", user.isEmailVerified());
userMap.put("providerData", Collections.unmodifiableList(providerData));
Expand Down
6 changes: 6 additions & 0 deletions packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,13 @@ - (NSMutableDictionary *)dictionaryFromUser:(FIRUser *)user {
for (id<FIRUserInfo> userInfo in user.providerData) {
[providerData addObject:toDictionary(userInfo)];
}

long creationDate = [user.metadata.creationDate timeIntervalSince1970];
long lastSignInDate = [user.metadata.lastSignInDate timeIntervalSince1970];

NSMutableDictionary *userData = [toDictionary(user) mutableCopy];
userData[@"creationTimestamp"] = [NSNumber numberWithLong:creationDate];
userData[@"lastSignInTimestamp"] = [NSNumber numberWithInt:lastSignInDate];
userData[@"isAnonymous"] = [NSNumber numberWithBool:user.isAnonymous];
userData[@"isEmailVerified"] = [NSNumber numberWithBool:user.isEmailVerified];
userData[@"providerData"] = providerData;
Expand Down
14 changes: 14 additions & 0 deletions packages/firebase_auth/lib/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import 'package:flutter/services.dart';
import 'package:meta/meta.dart';

/// Represents user data returned from an identity provider.
class FirebaseUserMetadata {
final Map<dynamic, dynamic> _data;

FirebaseUserMetadata._(this._data);

int get creationTimestamp => _data['creationTimestamp'];
int get lastSignInTimestamp => _data['lastSignInTimestamp'];
}

class UserInfo {
final Map<dynamic, dynamic> _data;

Expand Down Expand Up @@ -57,16 +67,20 @@ class UserUpdateInfo {
/// Represents a user.
class FirebaseUser extends UserInfo {
final List<UserInfo> providerData;
final FirebaseUserMetadata _metadata;

FirebaseUser._(Map<dynamic, dynamic> data)
: providerData = data['providerData']
.map<UserInfo>((dynamic item) => UserInfo._(item))
.toList(),
_metadata = FirebaseUserMetadata._(data),
super._(data);

// Returns true if the user is anonymous; that is, the user account was
// created with signInAnonymously() and has not been linked to another
// account.
FirebaseUserMetadata get metadata => _metadata;

bool get isAnonymous => _data['isAnonymous'];

/// Returns true if the user's email is verified.
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_auth/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS
like Google, Facebook and Twitter.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_auth
version: 0.6.0
version: 0.6.2

flutter:
plugin:
Expand Down

0 comments on commit e920cf7

Please sign in to comment.