dotnet/aspnetcore · warning

Please enter a username.

Error message

Please enter a username.

What it means

Thrown by fetchNewCredential() in the sample PasskeyUI app.js (line 32) when the username passed to register a new WebAuthn/passkey credential is empty. The /attestation/options endpoint requires a username to build the credential creation options (it becomes the credential's user.id/user.name), so the client guards early and throws before making the request.

Source

Thrown at src/Identity/samples/IdentitySample.PasskeyUI/wwwroot/app.js:32

    function enableRouteScripts() {
        Blazor.addEventListener('enhancednavigationend', executeScript);

        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', executeScript);
        } else {
            executeScript();
        }
    }

    // Define home page JS functionality.
    addRouteScript('/', async () => {
        let abortController;
        const form = document.getElementById('auth-form');
        const statusMessage = document.getElementById('status-message');

        async function fetchNewCredential(username) {
            if (!username) {
                throw new Error('Please enter a username.');
            }

            const optionsResponse = await fetch('/attestation/options', {
                method: 'POST',
                body: JSON.stringify({
                    username,
                }),
                headers: {
                    'Content-Type': 'application/json',
                },
                credentials: 'include',
            });
            const optionsJson = await optionsResponse.json();
            const options = PublicKeyCredential.parseCreationOptionsFromJSON(optionsJson);
            abortController?.abort();
            abortController = new AbortController();
            return await navigator.credentials.create({
                publicKey: options,

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. Ensure the username input has name="username" and is non-empty before submitting.
  2. Add client-side UI validation (disable the register button until a username is present, or validate on submit and show a message).
  3. If you renamed the field, update the FormData lookup or the guard to match the new name.
  4. Display the error in the status-message element so the user understands the input is required.

Example fix

// before
<input name="user" /> <!-- wrong name, FormData.get('username') → null -->

// after
<input name="username" required />
<button name="action" value="register" disabled id="btn-register">Register</button>
<script>document.getElementById('username').addEventListener('input', e => document.getElementById('btn-register').disabled = !e.target.value);</script>
Defensive patterns

Strategy: validation

Validate before calling

function readUsername(form: HTMLFormElement): string | null {
  const v = new FormData(form).get('username');
  return typeof v === 'string' && v.trim().length > 0 ? v : null;
}

Type guard

function isNonEmptyUsername(v: FormDataEntryValue | null): v is string {
  return typeof v === 'string' && v.trim().length > 0;
}

Prevention

When it happens

Trigger: The register submit button is clicked while the username input is empty; FormData(form).get('username') returns '' or null and fetchNewCredential throws 'Please enter a username.'.

Common situations: User clicks 'Register' without typing a username. Input's name attribute is not 'username' so FormData returns null even when text was entered. Validation feedback not shown before the WebAuthn ceremony. Copy of the sample script adapted without preserving the username field name.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/14fa7f30f187937e. Report an issue: GitHub.