问题
I'm creating a website where businesses can offer my service to their clients/users for free. For a business to add a user (under their business account), the business logs in and inputs one of their clients/users email. I then send the client/user email to firebase functions and programmatically create an account.
I would like to send this new user a email saying something like 'Account Created: Reset Password' etc., I could do this using sendPasswordResetEmail on the browser, but this function is not available on Firebase functions/admin.
The best option I can think of it to randomly generate a password for each new user (ie - 'ef53gs'), and share the new password in a Welcome Email, but I think it would be a better experience if the Welcome Email included a link to (re)set their password.
Any idea's how to make something like sendPasswordResetEmail work for firebase functions?
回答1:
We ran into the same issue since the firebase-admin
does not have a sendPasswordResetEmail()
like the firebase
SDK does. We ended up just using the firebase
client SDK on the server as well alongside the firebase-admin
. Works fine.
回答2:
The admin sdk has a generatePasswordResetLink
which will create the link for you but it's on you then to handle sending the email which you can do using any service you'd like such as mailgun or mandrill. This also gives you more control over the email template.
回答3:
This would be a multi-tenant or multi-level-admin type of app solution. Simply create a web interface where each business can add users to their service. You will need to use the Admin SDK (server) to generate the permissions for each businesses admin. See:
Control Access with Custom Claims and Security Rules
The Firebase Admin SDK supports defining custom attributes on user accounts. This provides the ability to implement various access control strategies, including role-based access control, in Firebase apps. These custom attributes can give users different levels of access (roles), which are enforced in an application's security rules.
回答4:
I think a rather better way to do that is to actually use the REST API to reset the users passwords from the admin without adding a client library to the admin site.
curl 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/getOobConfirmationCode?key=[API_KEY]' \
-H 'Content-Type: application/json' \
--data-binary '{"requestType":"PASSWORD_RESET","email":"[user@example.com]"}'
[API KEY] can be retrieved from Project Settings > add an app >> click web and you will get the configuration with a JSON, within the JSON there is an APIKey that is the one that you need to use.
来源:https://stackoverflow.com/questions/50979478/send-firebase-reset-password-email-after-account-created-on-server-admin