export default createMiddleware({ onRequest: [ async ({ locals, nativeEvent }) => { locals.pb = new PocketBase(process.env.SECURE_PB_URL); locals.pb.authStore.loadFromCookie( getHeader(nativeEvent, 'cookie') || '' ); try { locals.pb.authStore.isValid && (await locals.pb.collection('users').authRefresh()); } catch { locals.pb.authStore.clear(); } } ], onBeforeResponse: [ async ({ locals, request, nativeEvent }) => { appendHeader( nativeEvent, 'set-cookie', locals.pb.authStore.exportToCookie({ secure: false }) ); } ]});
response.headers.append( 'set-cookie', locals.pb.authStore.exportToCookie() );