I want to build an application where users just can register with "Invitation". Users already with account can send invitations to the specified e-mail addresses, then the app send an e-mail with a link to the registration where there's a token and just the specified e-mail address can be used.
So first, how to an "automated" e-mail from firebase, secondly, how to generate an unique registration token to the URL?
For sending email from Firebase, you can use a Cloud Function. There is an official sample on this topic: https://github.com/firebase/functions-samples/tree/Node-8/email-confirmation
As said by Martin Zeitler you can use the push()
method to generate a unique token and to create a record with the corresponding email. Then when the new user tries to register, you could check that his email corresponds to the token before registering him. You could do that via different ways: with Cloud Functions again, e.g. with an HTTPS Cloud Function (see https://firebase.google.com/docs/functions/http-events) or by creating a record in the database that triggers a Cloud Function (see https://firebase.google.com/docs/functions/database-events). In both cases, you would use the Admin SDK to register/create the user, see https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth and https://firebase.google.com/docs/auth/admin/manage-users#create_a_user
Update following your comment
For example, you could have a form where you ask the invited user to enter his email and the unique token he has received (you could open and pre-fill this form through the link sent in the email). When this form is submitted it creates a node in the Realtime Database and this node creation would trigger a Cloud Function that:
Concretely, let's imagine that upon form submission we create the following node:
- registrationRequests
-UID
-email: .....
-token: .....
you could have a Cloud Function along the following lines:
exports.createInvitedUser = functions.database.ref('/registrationRequests/{requestId}')
.onCreate((snap, context) => {
const createdData = snap.val();
const email = createdData.email;
const token= createdData.token;
//First action, verify email and token by reading the node of the database where you initially stored the email/token
//Second action, register the user by using admin.auth().createUser({})
//See https://firebase.google.com/docs/auth/admin/manage-users#create_a_user
})
think this might work with Firebase Invites .setDeepLink()
.
where the deep-link would have to deliver the custom token.
Sets the link into your app that is sent with invitations. Specify this to share specific content with the recipient or to otherwise present a custom experience when a user opens your app from an invitation.
only can provide a Java example:
public class DeepLinkActivity extends AppCompatActivity {
@Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
Uri uri = intent.getData();
String token = uri.getQueryParameter("inviteToken");
...
}
}
or with .getDynamicLink() method.
to create unique token, use .push()
, which then also permits later use of .hasKey()
.
not certain if Invites
is even available for Web
JavaScript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With