astro-integration.mjs 557 Bytes
import 'dotenv/config'
import oidcMiddleware, { fileStoreOptions } from './oidc-middleware.mjs'
import { allParams } 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(fileStoreOptions, allParams()))
        server.middlewares.use((req, res, next) => {
          req[ clientLocalsSymbol ] = res.locals
          next()
        })
      },
    },
  }
}