Skip to Content
Signet

Verification and reset

Email verification and password reset flows, their Tokens, and how to disable verification.

Signet uses single-use Tokens for both flows. Only their SHA-256 digests are stored, they are checked in constant time, and consumption is atomic. Verification Tokens live 24 hours; reset Tokens live 1 hour.

Config.AppURL must be set. The default templates build:

<AppURL>/verify?token=<RAW_TOKEN>
<AppURL>/reset?token=<RAW_TOKEN>

A user-facing app should serve those pages, extract token from the query string and call the matching HTTP endpoint. The raw Token is never stored, so it cannot be recovered later.

Verifying an email

  1. Sign-up sends a verification Token by default. You can also call POST /send-verification.
  2. The message links to /verify?token=....
  3. Call POST /verify-email with {"token":"<RAW_TOKEN>"} (or auth.VerifyEmail(ctx, signet.VerifyEmailInput{Token: raw})).

The Token is consumed on success; replay returns ErrTokenInvalid.

Resetting a password

  1. POST /send-password-reset with the email address issues a reset Token.
  2. The message links to /reset?token=....
  3. POST /reset-password with {"token":"...","new_password":"..."} sets the new verifier.

Before changing the verifier, Signet deletes all reset Tokens and all Sessions of that User, then sends the password-changed notification. A stolen link or an old Session cannot keep access after a successful reset.

Anti-enumeration

For an unknown email, both send endpoints return 200 without sending mail. They still generate and digest a Token and render a template so the work done is comparable to the registered-email path. Mail transport time itself remains a signal; eliminating that needs queued delivery, which Signet does not provide.

Disabling verification

Both fields are *bool and nil means true:

off := false
cfg.RequireVerifiedEmail = &off     // sign-in no longer checks verification
cfg.SendVerificationOnSignUp = &off // no verification Token or email

Set both for a password-only setup. See Configuration.

Templates and local development

EmailTemplates has three methods: VerifyEmail, ResetPassword and PasswordChanged. DefaultTemplates renders HTML with html/template and plain text with text/template; replace it via Config.Templates to use your own wording.

In local development the example apps use the console mailer, which prints the whole message to the backend terminal — that is where you find the raw Token. See Mail.

Changing your password

An authenticated User can change their own password with auth.ChangePassword(ctx, signet.ChangePasswordInput{UserID: user.ID, CurrentPassword: old, NewPassword: next}) or POST /change-password. The current password must match the credential Account; a mismatch returns ErrInvalidCredentials with no side effects. The new password is checked against Password.MinLength/MaxLength before anything is revoked.

On success Signet deletes all Tokens of the User (verification, reset, OAuth, refresh), revokes every Session, writes the new verifier, and sends the password-changed notification. An email failure is logged but does not fail the call. The HTTP endpoint requires a session cookie and CSRF token; the User ID always comes from the authenticated Session, never from the request body.

Changing your email

POST /change-email (authenticated, CSRF-protected) sends a single-use proof to the new address. The old address stays active until POST /verify-change-email consumes the token from the emailed link. On success the User's email changes and EmailVerified is cleared; the old address no longer works. The new address must still be unique at confirmation time.

Applications with a custom EmailTemplates implementation keep compiling: the optional EmailChangeTemplates interface supplies the change-email message, with a built-in default when it is not implemented.

Deleting an account

POST /request-account-deletion sends a single-use proof to the current email. POST /confirm-account-deletion consumes it and removes Sessions, all Tokens, Accounts and the User row in that order. A failure at any step is returned and leaves no live Session. The optional DeleteUserTemplates interface supplies the message, with a built-in default for existing EmailTemplates implementations.

Automatic sign-in

Normally verifying an email only marks the User verified. Applications can opt into issuing a Session at the same time:

cfg.AutoSignIn = &signet.AutoSignInConfig{
    AfterSignUp:       false,
    AfterVerification: true,
}

With AfterVerification enabled, use VerifyEmailAndSignIn instead of VerifyEmail:

result, err := auth.VerifyEmailAndSignIn(ctx, signet.VerifyEmailInput{Token: token})
// result.SessionToken is a normal Session; result.User is the verified User.

Automatic sign-in fires the normal sign-in hook and audit event with method email, records the Last sign-in method as email, and keeps the verification Token single-use. It never bypasses RequireVerifiedEmail: set AfterSignUp only when the email is already verified or verification is not required.

cfg.AutoSignIn = &signet.AutoSignInConfig{AfterSignUp: true}
cfg.RequireVerifiedEmail = signet.BoolPtr(false) // or send no verification email
result, err := auth.SignUp(ctx, signet.SignUpInput{Email: "user@example.com", Password: "correct horse"})
// result.SessionToken is set when the gate permits it.

On this page