There are significant problems with the accepted answer:
- It completely sidesteps the Firebase Console settings for password resets. If you have configured a custom email template or settings in the Firebase Console, those settings & template must be manually recreated in your implementation using
generatePasswordResetLink
. And now you are perpetually forced to keep your custom implementation in lockstep with your Firebase Console settings. This is not a great solution long-term.
- Your server must generate the temporary password for the user. This means that a user's login credentials can be known by someone other than the user themselves. Any Firebase admin, or developer with access to these APIs, could log into Firebase with these credentials and start commiting actions on behalf of the actual user. This is an unacceptable security practice, even temporarily. I am shocked that the Firebase SDKs even provide this functionality.
So here's an answer that, while technically not what the question asks for, does solve both of these problems with minimal fuss. Run npm install firebase
. Then run the below snippet:
import { FirebaseApp, initializeApp } from 'firebase/app'
import { Auth, getAuth, sendPasswordResetEmail } from 'firebase/auth'
const run = async ():Promise<boolean> => {
const firebaseApp:FirebaseApp = initializeApp({
apiKey: '**********', // Pull these values from your Firebase console
authDomain: '**********',
projectId: '**********',
storageBucket: '**********',
messagingSenderId: '**********',
appId: '**********',
measurementId: '**********'
})
const firebaseAuth:Auth = getAuth(firebaseApp)
let success:boolean = false
try {
await sendPasswordResetEmail(firebaseAuth, '[email protected]')
success = true
}
catch (e) {
console.error(e)
}
return success
}
run()
This will send the regular password reset email that is configured in the Firebase Console settings directly to the user themselves. Your server has no knowledge of the password reset details. No setting up a custom email templater, no custom SMTP settings; everything runs from what is configured in the single source of truth: Firebase Console.
I know the question specifically asks about the firebase-admin
SDK and the other answers do correctly call out that this functionality still does not exist there as of April 2024, but I am compelled to answer that this functionality is possible using the standard user firebase
SDK. If the developer has access to the firebase-admin
SDK settings, they likely will have access to the firebase
SDK settings as well.