https://supertokens.com/ logo
Title
v

Vaiva

12/15/2022, 4:36 PM
Hi. Is it possible in backendConfig when overwriting emailDelivery access userContext? I created new email verification template but I need to pass user's first name there. And when I try to access input.userContext I get this (picture). Although in frontend I did set userContext in a signUp function:
userContext:{ firstName: firstName}
r

rp

12/15/2022, 4:37 PM
Hey @Vaiva
The user context object doesn’t get transferred from the frontend to the backend. You can add the first name to the request object on the frontend by using the pre api hook
And the read that from the request object on the backend
You can access the request object on the backend via the userContext._default.request
v

Vaiva

12/15/2022, 4:43 PM
Thanks. I will try that
To which exact object in pre api hook I should put needed data? In requestInit in context? it consists of body, headers and method. But body isn't object. just string. Maybe I'm missing something..?
r

rp

12/16/2022, 11:54 AM
Yea. You can modify the body for example by JSON parsing it, adding your custom info, and stringifying it again
v

Vaiva

12/16/2022, 12:18 PM
I did update body's formFields and stringified it successfully. but I get error message:
Are you sending too many / too few formFields?
. So it looks like Supertokens doesn't allow to change request body?
r

rp

12/16/2022, 12:18 PM
oh right. You shouldn't update the formField prop. Add your own prop to the request body
if you want to update the formField, you can do that more easily. See this: https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/signup-form/adding-fields
v

Vaiva

12/16/2022, 12:49 PM
Okey I created new prop in request data. now payload from frontend is
{formField: [...], additionalInfo: [...]}
. But how can I access additionalInfo in the backend?
input
only gives me
{type: "...", user: {id: ... , email: ... }, emailVerifyLink: "...", userContext: {...}}
. when I printed
userContext._default.request
I got massive object but nowhere
additionalInfo
🤔
r

rp

12/16/2022, 12:51 PM
await userContext._default.request.getJSONBody()
. The type of request is this: https://github.com/supertokens/supertokens-node/blob/master/lib/ts/framework/request.ts