Hi. Is it possible in backendConfig when overwriti...
# support-questions
v
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
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
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
Yea. You can modify the body for example by JSON parsing it, adding your custom info, and stringifying it again
v
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
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
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
await userContext._default.request.getJSONBody()
. The type of request is this: https://github.com/supertokens/supertokens-node/blob/master/lib/ts/framework/request.ts
2 Views