Skip to content

Commit

Permalink
feat(auth, multi-tenant): expose user.tenantId in javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehardy committed Mar 12, 2021
1 parent 311427e commit 4f6d426
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,7 @@ private WritableMap firebaseUserToMap(FirebaseUser user) {
final String provider = user.getProviderId();
final boolean verified = user.isEmailVerified();
final String phoneNumber = user.getPhoneNumber();
final String tenantId = user.getTenantId();

userMap.putString("uid", uid);
userMap.putString("providerId", provider);
Expand Down Expand Up @@ -2000,6 +2001,12 @@ private WritableMap firebaseUserToMap(FirebaseUser user) {
userMap.putNull("phoneNumber");
}

if (tenantId != null && !"".equals(tenantId)) {
userMap.putString("tenantId", tenantId);
} else {
userMap.putNull("tenantId");
}

userMap.putArray("providerData", convertProviderData(user.getProviderData(), user));

WritableMap metadataMap = Arguments.createMap();
Expand Down
1 change: 1 addition & 0 deletions packages/auth/ios/RNFBAuth/RNFBAuthModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,7 @@ - (NSDictionary *)firebaseUserToDict:(FIRUser *)user {
@"providerData": [self convertProviderData:user.providerData],
keyProviderId: [user.providerID lowercaseString],
@"refreshToken": user.refreshToken,
@"tenantId": user.tenantID ? (id) user.tenantID : [NSNull null],
keyUid: user.uid
};
}
Expand Down
4 changes: 4 additions & 0 deletions packages/auth/lib/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export default class User {
return this._user.phoneNumber || null;
}

get tenantId() {
return this._user.tenantId || null;
}

get photoURL() {
return this._user.photoURL || null;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/auth/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ export namespace FirebaseAuthTypes {
* Returns the unique identifier of the provider type that this instance corresponds to.
*/
providerId: string;
/**
* Returns a string representing the multi-tenant tenant id. This is null if the user is not associated with a tenant.
*/
tenantId?: string;
/**
* Returns a user identifier as specified by the authentication provider.
*/
Expand Down Expand Up @@ -1247,6 +1251,7 @@ export namespace FirebaseAuthTypes {
* await firebase.auth().setTenantId('tenant-123');
* ```
*
* @error auth/invalid-tenant-id if the tenant id is invalid for some reason
* @param tenantId the tenantID current app bind to.
*/
setTenantId(tenantId: string): Promise<void>;
Expand Down

0 comments on commit 4f6d426

Please sign in to comment.