Session cookie not being set upon signup

I am using the email & password provider, I have a sign up process that includes verifying the email and adding 2fa by default through totp or an authernticator app. At first I call the email.singup method I get the created user data back The next step is to verify the email which works, an email is sent and the verification link works and the user table is updated. The next step is to enable 2fa and add an authenticator app, but when I call the enable function with the user's password I get a 401 back Im using next.js and trpc.
enable-2fa-step.tsx:61 POST http://localhost:3000/api/auth/two-factor/enable 401 (UNAUTHORIZED)

[APIError [BetterCallAPIError]: API Error: UNAUTHORIZED ] {
status: 'UNAUTHORIZED',
headers: Headers {},
body: { code: 'UNAUTHORIZED' },
[cause]: undefined
}
enable-2fa-step.tsx:61 POST http://localhost:3000/api/auth/two-factor/enable 401 (UNAUTHORIZED)

[APIError [BetterCallAPIError]: API Error: UNAUTHORIZED ] {
status: 'UNAUTHORIZED',
headers: Headers {},
body: { code: 'UNAUTHORIZED' },
[cause]: undefined
}
I have set the autoSignInAfterVerification to true, which helped with getting actual session cookies assigned, but I am still getting 401 back 🤦‍♂️ What am I doing wrong?
Solution:
When calling the auth.api on the server we need to pass the damn headers 🤦 ```ts const data = await auth.api.enableTwoFactor({ body: { password: input.password }, headers: await headers(),...
Jump to solution
1 Reply
Solution
VinnyXL(EU)
VinnyXL(EU)6d ago
When calling the auth.api on the server we need to pass the damn headers 🤦
const data = await auth.api.enableTwoFactor({
body: { password: input.password },
headers: await headers(),
});
const data = await auth.api.enableTwoFactor({
body: { password: input.password },
headers: await headers(),
});

Did you find this page helpful?