Skip to content

feat(auth, multi-tenant): add multi-tenant (tenantID) support #5004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from

Conversation

xianlinbox
Copy link
Contributor

@xianlinbox xianlinbox commented Mar 10, 2021

Description

When I working on the firebase auth, I found I can't set tenant id which is quite critical for working with Google Identity platform. In the repository discussion channel. there are 2 questions related with this also.

  1. Set tenantID on auth() #4462
  2. Multi Tenant Support #4964

Then I checked the Firebase iOS SDK, which actually provided tenantId for user to set it. So I created this PR to open this capability to React native Lib users.

Related issues

No

Release Summary

Support set tenant it in Firebase auth module.

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
  • My change includes tests;
    • e2e tests added or updated in packages/\*\*/e2e
    • jest tests added or updated in packages/\*\*/__tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan

yarn tests:jest

Test Suites: 8 passed, 8 total
Tests: 1 skipped, 96 passed, 97 total
Snapshots: 0 total
Time: 20.6 s


Think react-native-firebase is great? Please consider supporting the project with any of the below:

@vercel
Copy link

vercel bot commented Mar 10, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/invertase/react-native-firebase/BsJEQQhcE4zboGY5Xa3RoXs4YfFi
✅ Preview: https://react-native-f-git-fork-xianlinbox-support-set-tenant-in-89780f.vercel.app

@CLAassistant
Copy link

CLAassistant commented Mar 10, 2021

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ mikehardy
✅ xianlinbox
❌ Xianning Liu


Xianning Liu seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov
Copy link

codecov bot commented Mar 10, 2021

Codecov Report

Merging #5004 (56a6147) into master (06eebad) will decrease coverage by 0.36%.
The diff coverage is 16.67%.

@@            Coverage Diff             @@
##           master    #5004      +/-   ##
==========================================
- Coverage   89.09%   88.74%   -0.35%     
==========================================
  Files         109      105       -4     
  Lines        3721     3488     -233     
  Branches      348        0     -348     
==========================================
- Hits         3315     3095     -220     
- Misses        365      393      +28     
+ Partials       41        0      -41     

Copy link
Collaborator

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xianlinbox thank you so much for this! We have had some interest in it, but have not had time to implement it.

I made some comments about the shape of the API as I think it can be fully synchronous based on the underlying native APIs being synchronous.

Also I made some grammar comments but please understand I know how tough it is to speak multiple languages (you should hear me speak Spanish...), I hope you don't mind the suggestions

Finally, it appears the User object also has a read-only tenantId property that you could easily expose, do you think you could add that? It is apparently related to the app tenantId but could be independent (you can change app tenantId after users are associated with another tenantId, and I think multi-tenant users might need to know the user's tenantId)

https://firebase.google.com/docs/reference/swift/firebaseauth/api/reference/Classes/User#tenantid
https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser#public-abstract-string-gettenantid

I think user.tenantId may already be populated in the current user naturally, so it may just be a matter of copying it to the JS object from native and adding it to the types? Worst case, as a user is returned from native methods, you may need to call the tenantId getter in native code, then return it with the rest of the user information?

Finally, I really really appreciate that you added test code along with the change. That helps us so much.

Cheers

@mikehardy mikehardy added Workflow: Waiting for User Response Blocked waiting for user response. plugin: authentication Firebase Authentication type: enhancement Implements a new Feature labels Mar 10, 2021
@mikehardy
Copy link
Collaborator

Maintainer note: I verified that the multi-tenant support was added prior to our current native SDK minimum, this should be good to merge as feature release / non-breaking change once it is in shape

@mikehardy mikehardy changed the title feat(functions): support to set tenantID for firebase auth feat(auth, multi-tenant): add multi-tenant (tenantID) support Mar 10, 2021
@mikehardy mikehardy added Workflow: Needs Review Pending feedback or review from a maintainer. and removed Workflow: Waiting for User Response Blocked waiting for user response. labels Mar 10, 2021
@mikehardy mikehardy self-assigned this Mar 10, 2021
Copy link
Collaborator

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested a different wording of the documentation a little bit to explain why null might be returned, I will commit that one

The only other question I have is about this:

Finally, it appears the User object also has a read-only tenantId property that you could easily expose, do you think you could add that? It is apparently related to the app tenantId but could be independent (you can change app tenantId after users are associated with another tenantId, and I think multi-tenant users might need to know the user's tenantId)

https://firebase.google.com/docs/reference/swift/firebaseauth/api/reference/Classes/User#tenantid
https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser#public-abstract-string-gettenantid

I think user.tenantId may already be populated in the current user naturally, so it may just be a matter of copying it to the JS object from native and adding it to the types? Worst case, as a user is returned from native methods, you may need to call the tenantId getter in native code, then return it with the rest of the user information?

@mikehardy
Copy link
Collaborator

Oh - and the CLA is not signed yet - we will need the CLA signed (#5004 (comment)), it can merge now or if you have time to add user.tenantId we can merge after that, thanks @xianlinbox !

@mikehardy mikehardy added Workflow: Pending Merge Waiting on CI or similar Workflow: Waiting for User Response Blocked waiting for user response. Blocked: Missing CLA and removed Workflow: Needs Review Pending feedback or review from a maintainer. labels Mar 11, 2021
@xianlinbox
Copy link
Contributor Author

Oh - and the CLA is not signed yet - we will need the CLA signed (#5004 (comment)), it can merge now or if you have time to add user.tenantId we can merge after that, thanks @xianlinbox !

Thanks for the feedbacks and correct wording. I have clicked the link and signed the CLA. but I don't know why the PR didn't reflect that.
image

@mikehardy
Copy link
Collaborator

per the comment above it is typically when commit email address is different than github email address, and you have not associated the commit email address with your github account - this happens for some people

Xianning Liu seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.

@xianlinbox
Copy link
Contributor Author

@mikehardy as I need to updated the commit author to correct my email address, so I created a new PR (#5019) for this change. the code is same as this one. Can we move to that PR?

@xianlinbox xianlinbox closed this Mar 12, 2021
@xianlinbox xianlinbox deleted the support-set-tenant branch March 12, 2021 05:51
@mikehardy mikehardy removed the Workflow: Pending Merge Waiting on CI or similar label Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked: Missing CLA plugin: authentication Firebase Authentication type: enhancement Implements a new Feature Workflow: Waiting for User Response Blocked waiting for user response.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants