Server auth not working (SvelteKit) via signin with email

Hey everyone, When I try to sign in with email and with server actions, the session doesnt seem to set or authentication simply doesnt complete In this code: try { let res = await auth.api.signInEmail({ body: { email, password } }); console.log(res.user); } catch (err) { if (err instanceof APIError) { error(400, { message: err.message }); } } the user does get logged in the console but my session is still empty, Is this a bug? or am simply doing something wrong? Do we need to set the user session ? Thanks!
3 Replies
SheldonFromBBT
SheldonFromBBTOP4mo ago
In devtools there's no cookie set after signin I might be missing something obvious here Hey @bekacru can you please help me with this one?
bekacru
bekacru4mo ago
This issue occurs because auth.api calls don’t set cookies in server actions. Instead, you need to use the cookies helper from Next.js. I recommend making the component a client component and using the client instance instead. But, if you must use server actions, you’ll need to set asResponse to true in the call, parse the Set-Cookie headers, and manually set them using the cookie helper from next. We're planning to add a helper for this soon, but for now, that’s the only solution.
SheldonFromBBT
SheldonFromBBTOP4mo ago
Thanks! for the response, I did the workaround and it works well now, shouldn't this thing be documented ? As currently it doesn't tell what to do with that response object, and at first it seems like the session gets set automatically I'll open a pr soon for it

Did you find this page helpful?