PiVPN Web uses session-cookie-based authentication backed by express-session. Sessions are persisted in SQLite viaDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/AZhur771/pivpn-web/llms.txt
Use this file to discover all available pages before exploring further.
TypeormStore, so they survive process restarts as long as a stable SECRET environment variable is configured. The session cookie is issued with httpOnly: true and sameSite: strict. The secure flag is only set when the IS_SECURE environment variable is present, which is appropriate when the server sits behind a TLS-terminating proxy.
How It Works
POST /api/sessionwith a JSON body containingusernameandpassword.- The server looks up the user in SQLite and verifies the supplied password against its bcrypt hash.
- On success, a
Set-Cookieheader in the response delivers your session cookie. - Include that cookie in every subsequent request to authenticate.
- Call
DELETE /api/sessionto invalidate the session and log out.
Log In
Send your credentials as a JSON body to create a session:-c cookies.txt flag tells curl to save the returned Set-Cookie header to a cookie jar file. On success the server responds with 204 No Content.
The account login name. Corresponds to the
ADMIN_USER, VIEWER_USER, or TECH_USER environment variable used when provisioning the account.The account password in plain text. The server compares it against the bcrypt-hashed value stored in SQLite.
500 with { "error": "Missing username" } or { "error": "Missing password" }. If the credentials are wrong it returns 500 with { "error": "Wrong username or password" }.
Use the Session Cookie
Pass the saved cookie jar on every authenticated request with the-b flag:
Check Session Info
GET /api/session tells you whether the current cookie represents an authenticated session and, if so, which user is logged in:
true if the request carries a valid, recognised session cookie; false otherwise.The SSH username used to connect to the PiVPN host (the
SSH_USER environment variable). Only present when authenticated is true.The hostname of the PiVPN server, obtained by running
hostname over SSH. Only present when authenticated is true.true if the logged-in account has admin privileges; false for viewer accounts. Only present when authenticated is true.Role-Based Access
TheisAdmin field in the session response determines what operations the authenticated user may perform:
isAdmin: true— full access, including write operations: creating clients, deleting clients, enabling/disabling clients.isAdmin: false— read-only access. Calling any admin-only endpoint returns403 Forbiddenwith{ "error": "Not enough rights" }.
Log Out
Destroy the active session by sending aDELETE request. The server removes the session from SQLite and returns 204 No Content.
When making API requests from a browser-hosted web app on the same origin, pass This is exactly how the built-in PiVPN Web frontend communicates with the API.
credentials: 'include' in your fetch() calls so the browser automatically sends and receives the session cookie: