Photo Social App with FlutterFlow and Supabase · Course book
Chapter 30: Password Recovery
Sooner or later every user forgets a password. An app without a way to recover the account loses that user for good, so a reliable forgot and reset password flow is one of the first things a production app needs. This chapter builds it for the photo app with FlutterFlow and Supabase: the three pages involved, the custom actions written in a little Dart code that call Supabase's recovery functions, the configuration in Supabase that sends users back into the app, how the client application handles the returning link, and testing. It also explains why reset links are safe and why password rules matter, with the strength of passwords worked out by hand and shown in a graph.
How password recovery works
Password recovery proves identity through the email address instead of the forgotten password. The user enters their email on a forgot password page. Supabase generates a secret, single-use, time-limited token and emails a link containing it. When the user taps the link, it opens the app, or the web version, which uses the token to start a temporary recovery session. On the reset password page, the user chooses a new password, which the app saves to their account, and a success page confirms the change and leads back to the login screen.
| Step | Page | What happens | Supabase function |
|---|---|---|---|
| 1 | Forgot password | User enters email; app requests a reset email | resetPasswordForEmail, with a redirect address |
| 2 | User taps the link containing a one-time token | Supabase verifies the token | |
| 3 | Reset password | App opens with a recovery session; user enters a new password twice | updateUser with the new password |
| 4 | Success | Confirmation and a button to log in | Optionally sign out the recovery session |
The forgot password page should give the same response whether or not an account exists for the email, such as "If an account exists for that address, we have sent a link". Saying "No account found" would let anyone discover which emails are registered, a small privacy leak. Supabase also limits how often reset emails can be requested for one address, which stops the feature being used to flood someone's inbox.
Custom actions
FlutterFlow's built-in actions cover many authentication tasks, but recovery flows with deep links often need finer control, which custom actions provide. A custom action is a small Dart function added to the project; it can call the Supabase client directly and be used in action chains like any built-in action. This flow needs two.
// Custom action 1: send the reset email
Future sendResetEmail(String email) async {
await Supabase.instance.client.auth.resetPasswordForEmail(
email.trim(),
redirectTo: 'photoapp://reset-password',
);
}
// Custom action 2: save the new password during a recovery session
Future<bool> updatePassword(String newPassword) async {
final res = await Supabase.instance.client.auth.updateUser(
UserAttributes(password: newPassword),
);
return res.user != null;
}
The redirectTo value tells Supabase where the link should send the user. For a mobile app it is a deep link using the app's own scheme, here photoapp://, which phones route to the installed app; for the web version it is the address of the reset page. The second action returns whether the update succeeded, so the page can show the success page or an error. Custom actions should catch errors and return a clear result rather than crash, and they should never contain secret keys: the client already holds the public anon key and the user's session.
The three pages
The forgot password page, reached from a "Forgot password?" link on the login page, holds an email field and a "Send reset link" button. Its action validates the email, runs the first custom action, then shows the neutral confirmation message and perhaps a "Back to login" button. Disabling the button for a short time after sending prevents repeated requests.
The reset password page opens from the link. It has two password fields, new and confirm, with the same rules as sign-up: a minimum length, and the two must match. Showing the rules as the user types, ticking each as it is met, helps people choose a good password the first time. The Save button runs the second custom action and, on success, navigates to the success page, replacing the reset page so the back button cannot return to it.
The success page confirms "Your password has been changed" and offers a button to log in. Some apps sign the user in directly instead; either way, the recovery session should not linger longer than needed.
A password change is also a security event, so it is good practice to tell the user about it. Supabase can send a notification email when a password changes, and the app can sign out other devices that were using the old session, so that if someone else had access to the account, they lose it the moment the real owner resets the password. Signed-in users who simply want to change their password, rather than recover a forgotten one, can use the same reset page reached from their settings, with the extra step of re-entering the current password first, which stops someone using an unlocked phone to take over the account.
Configuring Supabase and the client
Supabase only redirects to addresses it trusts. In the project's authentication settings, the site URL and the list of redirect URLs must include every address the app uses: the deep link scheme for the phone app and the web address of the reset page. A link that tries to redirect anywhere else is refused, which stops attackers using your reset emails to send people to their own sites. The email template for password recovery can be edited there too, with the app's name and a clear button.
On the phone, the app must be registered to open links with its scheme, a setting in FlutterFlow's project configuration that adds the scheme to the iOS and Android builds. When the link opens the app, the Supabase client reads the token from the link, exchanges it for a recovery session and reports an authentication event signalling password recovery. The app listens for that event and navigates to the reset page. On the web, the same thing happens when the reset page loads with the token in its address. Handling this event in one place, at the app's start, ensures the reset page appears however the link was opened.
Links can arrive on a different device from the one that requested them, for example when someone requests a reset on their phone but opens the email on a laptop. The web version of the reset page handles this case, which is one reason to include the web address in the redirect list even for an app used mostly on phones. Testing both paths, phone to phone and phone to computer, catches redirect mistakes before users find them.
Why reset links are safe, and why password rules matter
A reset token is long and random, far too large a number to guess, it works only once, and it expires after a short time, often an hour. Someone would need access to the user's email inbox to use it, which is exactly the proof of identity the flow relies on. The weak point is the new password itself, which is why the reset page enforces the same rules as sign-up.
Testing the flow means trying it for real: request a reset for an existing account, open the email on the phone, follow the link into the app, set a new password, and log in with it. Then try the edge cases: an unknown email, which should show the same neutral message; a mismatched confirmation; a link used twice; and a link opened after it expires, which should explain clearly and offer to send a new one.
Practice tasks
- Compute the entropy of a random 12-character password using letters and digits.
- Why should the forgot password page give the same message whether or not the email is registered?
- What must be added to Supabase's redirect URLs for both the phone app and the web version?
- Explain what a deep link is and how the app knows to open the reset page.
- List four test cases for the reset flow, including at least two failures.
- Why should custom actions never contain the service role key?
This course book is available to read online only at tech-academy.chrysolites.org.