Clarification in documentation on setting cookies #77
Answered
by
jweatherby
jweatherby
asked this question in
Q&A
-
Hi! I'm getting started with sveltekit and trpc and am really happy so far! I'm just a bit stuck on how to best set cookies from a mutation. I have a pretty standard pattern, but couldn't find information in the docs on Authentication on how to best translate this bit of code into sveltekit-trpc as the result of a mutation:
Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
jweatherby
Mar 19, 2023
Replies: 1 comment
-
Update: I was able to figure this out with the following: // hooks.server.ts
const trpcHandle = createTRPCHandle({
router, createContext, responseMeta: (ctx) => {
const { data: [{ error, result }], paths } = ctx
let headers
if (paths?.includes('account.login') && !error) {
headers = {
'Set-Cookie': buildCookie(/* ...result.data */)
}
}
return { headers }
}
}); Not sure if this is the best approach, but it does the trick. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
icflorescu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: I was able to figure this out with the following:
Not sure if this is the best approach, but it does the trick.