-
Notifications
You must be signed in to change notification settings - Fork 1
auth basic HowTo
GitHub Action edited this page May 21, 2026
·
1 revision
This guide covers how to set up Basic HTTP Authentication for your Quatrain API servers.
You can protect any Quatrain API server by initializing the AuthBasic adapter and injecting its middleware into your ServerAdapter.
import { ExpressAdapter } from '@quatrain/api-server-express'
import { AuthBasic } from '@quatrain/auth-basic'
import { Api } from '@quatrain/api'
// 1. Initialize your server adapter
const server = new ExpressAdapter(undefined, { apiPrefix: '/api' })
Api.addServer(server, 'default')
// 2. Initialize Basic Auth with credentials
const basicAuth = AuthBasic.factory(process.env.ADMIN_USER, process.env.ADMIN_PASS)
// 3. Attach the middleware to your server instance
if (basicAuth) {
server.addMiddleware(basicAuth.middleware())
}In Core Studio, you can easily protect your deployment without writing any code. Just define the STUDIO_AUTH_USER and STUDIO_AUTH_PASS environment variables.
For example, in your compose.yaml file:
services:
studio-api:
image: ghcr.io/quatrain/studio-image:latest
environment:
- STUDIO_AUTH_USER=admin
- STUDIO_AUTH_PASS=supersecretThe server will automatically detect these variables and enable Basic Authentication for all incoming requests as a fallback to the dynamic authentication loading.