Duvet DOCS
GitHub

Authentication

Register

POST /api/auth/signin

Create a new user account and send a verification email. The account is created even if the email can't be sent; the user can ask for another one with Resend Verification Email.

JSON Body

FieldTypeDescription
username stringUnique username
email stringValid email address
password stringPassword (min 8 characters)
alias ?string?Display name

Returns: 201 Created, with no body. Log in with POST /api/auth/login to get tokens.

Errors: 409 with email is already in use or that username is taken.

Log In

POST /api/auth/login

Authenticate with email and password. Returns an access token and sets a session cookie.

JSON Body

FieldTypeDescription
email stringEmail address
password stringAccount password
device ?stringDevice name for session tracking
browser ?stringBrowser name for session tracking
os ?stringOperating system for session tracking

Response

FieldTypeDescription
token stringAccess token (Bearer)
session_token stringSession refresh token

Returns: AuthTokenResponse (access + refresh tokens).

Errors: 400 with {"error": "invalid email or password"} when the email or the password is wrong (the same message for both, so it doesn't reveal which accounts exist). After 10 attempts for an address within 15 minutes without a successful one, 429 with {"error": "too many failed login attempts, try again later"}, even with the right password, until 15 minutes have passed since the first failure (see Rate Limiting).

Refresh Session

POST /api/auth/refresh

Refresh the current session. Reads the session token from the X-Session-Token header, or from the duvet_session_token cookie when there's no header. Returns a new access token and rotates the session token. Refreshes of one session that overlap all get the same new tokens: for 30 seconds after a rotation, the previous session token refreshes to the current tokens. After that, or once the session is logged out, it answers 401. The new tokens last 24 hours, but a session ends 30 days after its login: from then on, refreshing it answers 401 and the user has to log in again.

Response

FieldTypeDescription
token stringNew access token (Bearer)
session_token stringRotated session refresh token

Returns: AuthTokenResponse (access + refresh tokens).

Log Out

POST /api/auth/logout

Revoke the current session token (from the X-Session-Token header, or else the cookie) and clear the session cookie.

Returns: 204 No Content

Verify Email

POST /api/auth/verify

Verify a user's email address using a one-time token sent via email.

JSON Body

FieldTypeDescription
token stringEmail verification token

Returns: 204 No Content

Resend Verification Email

POST /api/auth/verify/send

Send a new email verification token to the authenticated user. Requires authentication. At most 3 per hour per account.

Returns: 204 No Content

Errors: 409 when the email is already verified, 400 for an account without an email, and 502 when the email couldn't be sent.

Reset Password

POST /api/auth/reset-password

Reset a password using a password reset token.

JSON Body

FieldTypeDescription
token stringPassword reset token
password stringNew password (min 8 characters)

Every session of the account ends: its tokens stop working, and its gateway connections are closed with code 4004.

Returns: 204 No Content

Send Reset Password Email

POST /api/auth/reset-password/send

Send a password reset email to the authenticated user. Requires authentication. At most 3 per hour per account.

Returns: 204 No Content

Errors: 400 for an account without an email, and 502 when the email couldn't be sent.

Forgot Password

POST /api/auth/forgot-password

Request a password reset email by providing an email address. Always returns success to avoid revealing whether the email exists. Sends at most 3 emails per address per hour; requests past that still succeed but send nothing.

JSON Body

FieldTypeDescription
email stringAccount email address

Returns: 204 No Content

Change Email

POST /api/auth/change-email

Update the user's email address using a verification token and the new email.

JSON Body

FieldTypeDescription
token stringEmail change verification token
email stringNew email address

Returns: 204 No Content

Send Change Email Verification

POST /api/auth/change-email/send

Send a verification email to initiate an email address change. Requires authentication. At most 3 per hour per account.

JSON Body

FieldTypeDescription
email stringNew email address to verify

Returns: 204 No Content

Errors: 409 when the address is already yours or belongs to a verified account, and 502 when the email couldn't be sent.