@@ -36,7 +36,7 @@ export function defineOAuthBlueskyEventHandler({ config, onSuccess, onError }: O
3636 const clientMetadata = getAtprotoClientMetadata ( event , 'bluesky' , config )
3737 const scopes = clientMetadata . scope ?. split ( ' ' ) ?? [ ]
3838
39- const sessionStore = new SessionStore ( event )
39+ const sessionStore = new SessionStore ( )
4040 const stateStore = new StateStore ( event )
4141
4242 const client = new NodeOAuthClient ( {
@@ -86,12 +86,12 @@ export function defineOAuthBlueskyEventHandler({ config, onSuccess, onError }: O
8686
8787 try {
8888 const { session } = await client . callback ( new URLSearchParams ( query as Record < string , string > ) )
89- const sessionInfo = await sessionStore . get ( )
89+ const sessionInfo = await sessionStore . get ( session . did )
9090 const profile = scopes . includes ( 'transition:generic' )
9191 ? ( await new Agent ( session ) . getProfile ( { actor : session . did } ) ) . data
9292 : null
9393
94- sessionStore . del ( )
94+ sessionStore . del ( session . did )
9595
9696 return onSuccess ( event , {
9797 user : profile ?? { did : session . did } ,
@@ -111,7 +111,7 @@ export function defineOAuthBlueskyEventHandler({ config, onSuccess, onError }: O
111111}
112112
113113export class StateStore implements NodeSavedStateStore {
114- private readonly stateKey = 'oauth: bluesky:stat '
114+ private readonly stateKey = 'oauth- bluesky-state '
115115
116116 constructor ( private event : H3Event ) { }
117117
@@ -122,7 +122,12 @@ export class StateStore implements NodeSavedStateStore {
122122 }
123123
124124 async set ( key : string , val : NodeSavedState ) {
125- setCookie ( this . event , this . stateKey , btoa ( JSON . stringify ( val ) ) )
125+ setCookie ( this . event , this . stateKey , btoa ( JSON . stringify ( val ) ) , {
126+ path : '/' ,
127+ httpOnly : true ,
128+ secure : true ,
129+ sameSite : 'lax' ,
130+ } )
126131 }
127132
128133 async del ( ) {
@@ -131,21 +136,18 @@ export class StateStore implements NodeSavedStateStore {
131136}
132137
133138export class SessionStore implements NodeSavedSessionStore {
134- private readonly sessionKey = 'oauth:bluesky:session'
135-
136- constructor ( private event : H3Event ) { }
139+ private store : Record < string , NodeSavedSession > = { }
137140
138- async get ( ) : Promise < NodeSavedSession | undefined > {
139- const result = getCookie ( this . event , this . sessionKey )
140- if ( ! result ) return
141- return JSON . parse ( atob ( result ) )
141+ async get ( key : string ) : Promise < NodeSavedSession | undefined > {
142+ return this . store [ key ]
142143 }
143144
144145 async set ( key : string , val : NodeSavedSession ) {
145- setCookie ( this . event , this . sessionKey , btoa ( JSON . stringify ( val ) ) )
146+ this . store [ key ] = val
146147 }
147148
148- async del ( ) {
149- deleteCookie ( this . event , this . sessionKey )
149+ async del ( key : string ) {
150+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
151+ delete this . store [ key ]
150152 }
151153}
0 commit comments