Adding password recovery
There are two things missing for a complete picture of authentication: the ability to register a new user account and the typical password recovery feature. Registration is covered in the next chapter, but we will look at the password recovery feature now.
Password recovery works in the exact same way as magic links, except for two differences:
- After successfully clicking the Magic (Recovery) Link, you should forward the user to a page where the password can be changed (otherwise, it would be just the same as the magic link).
- To be able to tell the different scenarios apart, we use
type: "recovery"
instead oftype: "magiclink"
for generating the token, though it’s effectively the same. For the built-in mailing system (which we don’t use), this ensures that aPASSWORD_RECOVERY
event is fired when used on the frontend (onAuthStateChange
), such that you could redirect to a page where the user can set the password...