-
Notifications
You must be signed in to change notification settings - Fork 1
auth HowTo
GitHub Action edited this page Apr 21, 2026
·
1 revision
This guide demonstrates how to secure your application using the Quatrain authentication abstraction.
Configure the adapter once during application startup.
import { Auth } from '@quatrain/auth'
import { FirebaseAuthAdapter } from '@quatrain/auth-firebase'
const authAdapter = new FirebaseAuthAdapter({
config: { /* Firebase credentials */ }
})
// Register as the default auth provider
Auth.addAdapter('default', authAdapter, true)Use the adapter in your API middleware to protect routes.
import { Auth } from '@quatrain/auth'
async function authenticateRequest(req, res, next) {
const authHeader = req.headers.authorization
if (!authHeader || !authHeader.startsWith('Bearer ')) {
return res.status(401).send('Unauthorized')
}
const token = authHeader.split(' ')[1]
const auth = Auth.getAdapter()
try {
// verifyToken returns a normalized user object
const user = await auth.verifyToken(token)
req.user = user // Attach to request context
next()
} catch (err) {
res.status(403).send('Invalid token')
}
}