@@ -52,14 +52,25 @@ type CreateConfigOptions = {
5252 options ?: AtAstroOptions
5353}
5454
55- export function createConfig ( { isDev, astroConfig, options } : CreateConfigOptions ) : AtAstroConfig {
56- const rawSite = options ?. site ?? astroConfig . site
57- if ( ! rawSite )
55+ function resolveSite ( site : string | undefined ) : string {
56+ if ( ! site )
5857 throw new Error (
5958 "`site` is required, either on the root Astro config or in the integration options. " +
6059 "The site is used to generate the OAuth client metadata." ,
6160 )
62- const siteURL = new URL ( rawSite )
61+ return site
62+ }
63+
64+ function createSessionPrefix (
65+ options : AtAstroOptions | undefined ,
66+ site : string | undefined ,
67+ ) : string {
68+ const siteURL = new URL ( resolveSite ( options ?. site ?? site ) )
69+ return options ?. sessionPrefix ?? options ?. name ?? siteURL . hostname . replace ( / \. / g, "-" )
70+ }
71+
72+ export function createConfig ( { isDev, astroConfig, options } : CreateConfigOptions ) : AtAstroConfig {
73+ const siteURL = new URL ( resolveSite ( options ?. site ?? astroConfig . site ) )
6374 const site = siteURL . origin
6475 if ( ! astroConfig . server . host ) {
6576 throw new Error (
@@ -68,8 +79,7 @@ export function createConfig({ isDev, astroConfig, options }: CreateConfigOption
6879 )
6980 }
7081 const clientUri = isDev ? `http://${ astroConfig . server . host } :${ astroConfig . server . port } ` : site
71- const sessionPrefix =
72- options ?. sessionPrefix ?? options ?. name ?? siteURL . hostname . replace ( / \. / g, "-" )
82+ const sessionPrefix = createSessionPrefix ( options , site )
7383 const redirectUri = `${ clientUri } /oauth/callback`
7484 const scope = ( [ "atproto" , ...( options ?. scopes ?? [ ] ) ] satisfies AtprotoOAuthScope [ ] ) . join ( " " )
7585
@@ -170,14 +180,19 @@ export default function createPlugin(options?: AtAstroOptions): AstroIntegration
170180 prerender : false ,
171181 } )
172182 } ,
173- "astro:config:done" : ( { injectTypes } ) => {
183+ "astro:config:done" : ( { injectTypes, config } ) => {
184+ const sessionPrefix = createSessionPrefix ( options , config . site )
185+
174186 injectTypes ( {
175187 filename : "at-astro-locals.d.ts" ,
176188 content : `declare namespace App {
177- interface Locals {
178- getATProtoClient: import("at-astro/middleware").GetATProtoClientFn
179- }
180- }` ,
189+ interface Locals {
190+ getATProtoClient: import("at-astro/middleware").GetATProtoClientFn
191+ }
192+ interface SessionData {
193+ "${ sessionPrefix } :did": string
194+ }
195+ }` ,
181196 } )
182197 } ,
183198 } ,
0 commit comments