Use case
I have 2 pages, one where users enter their username, after which it's checked whether they are authenticated by an identity provider, or whether they need to provide their password. In the first case, the user is sent to that idendity provider. In the last case, the user is navigated to the 2nd page with a password input.
Problem
I want the browser to remember the username and optionally the password in both cases. It's already working where the user also needs to enter a password, using a hidden username input field on the 2nd page. In this case, the username/password is remembered after page 2, but also autofilled on page 1.
But when the user is authenticated elsewhere, then the browser doesn't autofill the username. It does show a dropdown with previously entered values, though. But I want it to autofill the username the same way it does when a user is authenticated with password.
What I've tried so far
- add an empty, hidden password input on page 1. Doesn't work.
- add a password input field to the 1st page with a dummy value and move it offscreen. Why this isn't the solution: the browser asks the user if it should store the username and dummy password. This is ugly, and when the user does need to provide a password, they are asked whether the password should be updated (with the dummy value), every time the user logs in.
I prefer not to use localStorage to implement my own autocomplete. If the browser supports autofilling username only, than that would be nicest, because then the user can also manage it using the browser's credential manager.
Question
How do I get the browser to remember and autofill the username, even when the user never provides a password?