JSPM

@kitiumai/auth-postgres

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 31
  • Score
    100M100P100Q75055F
  • License MIT

PostgreSQL storage adapter for Kitium Auth

Package Exports

  • @kitiumai/auth-postgres
  • @kitiumai/auth-postgres/dist/index.js
  • @kitiumai/auth-postgres/dist/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@kitiumai/auth-postgres) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@kitium/auth-postgres (PostgreSQL Storage Adapter)

PostgreSQL storage adapter for Kitium Auth core.

  • Persists users, sessions, organizations, API keys, email verification tokens, and auth events
  • Designed to be used with @kitium/auth

Install

npm install @kitium/auth-postgres pg

Usage

import { AuthCore } from '@kitium/auth'
import { PostgresStorageAdapter } from '@kitium/auth-postgres'
import { RedisCacheAdapter } from '@kitium/auth-redis' // optional
import { StripeBillingAdapter } from '@kitium/auth-stripe' // optional

const storage = new PostgresStorageAdapter(process.env.DATABASE_URL!, {
  ssl: process.env.PGSSL === 'true'
})
const cache = new RedisCacheAdapter(process.env.REDIS_URL!) // optional
const billing = new StripeBillingAdapter(process.env.STRIPE_SECRET_KEY!, process.env.STRIPE_WEBHOOK_SECRET) // optional

const auth = new AuthCore(storage, {
  jwtSecret: process.env.JWT_SECRET!,
  cache,
  billing,
  providers: [
    { id: 'google', type: 'oauth', clientId: process.env.GOOGLE_ID!, clientSecret: process.env.GOOGLE_SECRET! }
  ]
})

await auth.initialize()

Connection and Schema

  • The adapter manages a pg.Pool internally and creates tables/indexes on connect() if they don’t exist.
  • Minimal configuration: pass connectionString and optional pg options.

Common Operations

// Users
const user = await storage.createUser({ email: 'a@b.com', name: 'Alice' })
const fetched = await storage.getUser(user.id)
await storage.updateUser(user.id, { name: 'Alice B', plan: 'pro' })
await storage.deleteUser(user.id)

// API keys
const key = await storage.createApiKey({ principalId: 'user_1', hash: '...', prefix: 'kit', lastFour: 'abcd', scopes: ['api.read'], metadata: {}, expiresAt: null, updatedAt: new Date() })
const byHash = await storage.getApiKeyByHash('...')
await storage.updateApiKey(key.id, { scopes: ['api.read', 'api.write'] })
await storage.deleteApiKey(key.id)

// Sessions
const session = await storage.createSession({ userId: 'user_1', orgId: undefined, plan: 'free', entitlements: ['api.read'], expiresAt: new Date(Date.now() + 3600_000), metadata: {}, updatedAt: new Date() })
const s = await storage.getSession(session.id)
await storage.updateSession(session.id, { plan: 'pro' })
await storage.deleteSession(session.id)

// Organizations
const org = await storage.createOrganization({ name: 'ACME', plan: 'pro', seats: 10, members: [], metadata: {} })
const o = await storage.getOrganization(org.id)
await storage.updateOrganization(org.id, { seats: 20 })
await storage.deleteOrganization(org.id)

// Email verification tokens
const t = await storage.createEmailVerificationToken({ email: 'a@b.com', code: '123456', codeHash: '...', type: 'login', userId: undefined, metadata: {}, expiresAt: new Date(), usedAt: undefined, createdAt: new Date() })
await storage.markEmailVerificationTokenAsUsed(t.id)
await storage.deleteExpiredEmailVerificationTokens()

Testing

  • The package ships with Jest tests; run from this package:
npm test

Notes

  • Ensure your DATABASE_URL (or connection string) points to a Postgres instance with network access.
  • In production, manage schemas and migrations according to your environment policies.

License

MIT