@pietervdwerk/auth-astro
Version:
Auth Astro is the easiest way to add Authentication to your Astro Project. It wraps the core of [Auth.js](https://authjs.dev/) into an Astro integration which automatically adds the endpoints and handles everything else.
35 lines (31 loc) • 786 B
text/typescript
import type { AuthConfig } from '@auth/core/types'
import type { PluginOption } from 'vite'
export const virtualConfigModule = (config: AstroAuthConfig): PluginOption => {
const virtualModuleId = 'auth:config'
const resolvedId = '\0' + virtualModuleId
return {
name: 'auth-astro-config',
resolveId: (id) => {
if (id === virtualModuleId) {
return resolvedId
}
},
load: (id) => {
if (id === resolvedId) {
return `export default ${JSON.stringify(config)}`
}
},
}
}
export interface AstroAuthConfig extends AuthConfig {
/**
* Defines the base path for the auth routes.
* @default '/api/auth'
*/
prefix?: string
/**
* Defineds wether or not you want the integration to handle the API routes
* @default true
*/
injectEndpoints?: boolean
}