I am developing the app which has grouping function. Now I have the problem about adding new member in group.
Like Slack, in group creating onboarding flow user can decide group name and add members which don't use the app yet. As adding members function, I want to use inviting mail link using firebase dynamic links.
Data structure is below
User
- id
- name
- email
Group
- id
- groupName
- members[]
Group's members array has user id. But when someone creates new group, it is possible that new users don't register the app yet. So they don't have user id property in the app.
How do I fix this problem? When someone creates new group, should I develop sign up functions new user using Firebase auth? This means then new member has automatically user id, and adding those to members property. Or should group member array have mail address instead of user id.
Please tell me. I'm happy with Swift or JavaScript you will teach me. Thank you.
CodePudding user response:
I always use userId to achive this kind of feature, you can use anonymous authentication to get userId after user click invite link, Then if needed unlock more feature with furter authentication(add more provider).
If you only using mail address without authentication, It's hard to write rules for prevent user access unwanted data, Like anyone knew your email are able to access your account.
CodePudding user response:
UPDATE
After reading your comment I would propose another approach.
When the Group creator user adds users to a group, if a user does not already exists you could, from the front-end, call a Callable Cloud function that creates a temporary Firestore document in a specific collection. The ID of this document will be the user Id.
Then you send an email to the email address (you need to generate yourself the email, for example with the email extension) with a link containing the userId as query string value.
When the email recipient clicks on the link, you open a specific page of your web app that shows a set of fields for the future user to enter his password, display name etc. Then on clicking on a sign-in button in this page you call a Callable Cloud Function passing it the Firestore document ID plus the field values (the document ID is in query string). This Cloud Function creates the user in the Authentication service (using the Admin SDK) and flag the Firestore document as treated. Upon getting back the Cloud Function result in the web app you authenticate the user (you have his email an password, since he/she entered it in the form).
I’m using this exact approach for a B2B collaborative web app in which users can invite new users by email.
(I’m currently writing on a smart phone so it’s not easy to add links to the different documentation items but you’ll find the technical details in the doc, in particular for Callable Cloud Functions)
INITIAL ANSWER
(Totally different from the update)
So they don't have user id property in the app… How do I fix this problem? When someone creates new group, should I develop sign up functions new user using Firebase auth?
You can use the Anonymous Authentication mode, it exactly corresponds to your needs:
You can use Firebase Authentication to create and use temporary anonymous accounts to authenticate with Firebase. These temporary anonymous accounts can be used to allow users who haven't yet signed up to your app to work with data protected by security rules. If an anonymous user decides to sign up to your app, you can link their sign-in credentials to the anonymous account so that they can continue to work with their protected data in future sessions.
When signing-in with Anonymous Authentication a userId (uid
) will be created and later you will be able to convert an anonymous account to a permanent account