Shiba Bop
Shiba Bop
Explore posts from servers
SSolidJS
Created by Shiba Bop on 6/8/2024 in #support
access event.locals from a server function
appendHeader and getHeader did help somewhat but it was an order of operations issue, I ended up doing this:
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
})
);
}
]
});
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
})
);
}
]
});
and it works!
7 replies
SSolidJS
Created by Shiba Bop on 6/8/2024 in #support
access event.locals from a server function
it doesnt seem to actually set the cookie
7 replies
SSolidJS
Created by Shiba Bop on 6/8/2024 in #support
access event.locals from a server function
im actually having issue with this line
response.headers.append(
'set-cookie',
locals.pb.authStore.exportToCookie()
);
response.headers.append(
'set-cookie',
locals.pb.authStore.exportToCookie()
);
7 replies
SSolidJS
Created by Shiba Bop on 6/8/2024 in #support
access event.locals from a server function
that was it thanks!
7 replies