Skip to Content
Signet

Username and account management

Username sign-in, safe account listing and guarded unlinking.

A Username is a human-chosen identifier represented as an Account, so it requires no database migration. Account listing and unlinking use the existing Account Store methods.

Username sign-in

Set Config.Username (UsernameConfig) to control normalization and validation. The default normalizer lowercases the name; the default validator accepts [a-z0-9_.] with 3–30 characters. Reserved names are optional and checked after normalization.

cfg.Username = &signet.UsernameConfig{
    MinLength: 3,
    MaxLength: 30,
    Reserved:  []string{"admin", "root"},
}

Pass Username at sign-up and use it instead of email at sign-in:

_, err := auth.SignUp(ctx, signet.SignUpInput{
    Email: "ada@example.com", Password: "correct horse", Username: "Ada.Lovelace",
})
result, err := auth.SignIn(ctx, signet.SignInInput{
    Username: "ADA.LOVELACE", Password: "correct horse",
})

An invalid name returns ErrInvalidUsername (invalid_input), and a name already owned by another User returns ErrUsernameTaken (username_taken, 400). Failed sign-in is generic — a wrong password and an unknown Username both return ErrInvalidCredentials.

Listing and unlinking

ListAccounts(ctx, ListAccountsInput) (*ListAccountsResult, error) returns safe AccountInfo fields only: ID, provider, provider user ID, email, verification flag and creation time. No password verifier or token material is ever returned.

result, err := auth.ListAccounts(ctx, signet.ListAccountsInput{UserID: userID})

UnlinkAccount(ctx, UnlinkAccountInput) error requires a Session created within Accounts.FreshWindow (default five minutes). It rejects foreign Account IDs with ErrNotFound and refuses to remove the last Account with ErrLastAccount (last_account, 400), because a Second factor alone cannot sign in.

err := auth.UnlinkAccount(ctx, signet.UnlinkAccountInput{
    UserID: userID, AccountID: accountID, SessionToken: sessionToken,
})

Programmatic callers supply the raw Session token; the HTTP adapter derives it from the session cookie. A successful unlink flushes any configured Session cache.

A Username cannot currently be changed or added after sign-up: unlinking the Username Account leaves the User signing in by email only, and no bundled method creates a Username Account for an existing User. Applications that need renames own that flow — it means writing the replacement provider: "username" Account (normalised and globally unique) through the Store and removing the old one under one freshness guard.

HTTP endpoints

EndpointMethodAuthPurpose
accountsGETyesList safe Account fields.
unlink-accountPOSTyesUnlink one Account; requires CSRF and a fresh Session.

See HTTP API.

On this page