astro-integration.mjs 569 Bytes
import 'dotenv/config'
import oidcMiddleware, { fileStoreOptions } from './oidc-middleware.mjs'
import { oidcParams } from './options.mjs'

const clientLocalsSymbol = Symbol.for("astro.locals")

export default (options) => {
  return {
    name: 'session',
    hooks: {
      'astro:server:setup': async ({ server }) => {
        server.middlewares.use(await oidcMiddleware({ oidc: oidcParams() }, fileStoreOptions))
        server.middlewares.use((req, res, next) => {
          req[ clientLocalsSymbol ] = res.locals
          next()
        })
      },
    },
  }
}