https://supertokens.com/ logo
h

hoffeman

07/04/2022, 11:19 AM
I'm thinking it could have something to do with express 4. To set headers in express 4: res.set(key,value). But looking at this it seems it tries setting the header with methods res.header and res.setHeader. https://github.com/supertokens/supertokens-node/blob/master/lib/ts/framework/utils.ts
r

rp

07/04/2022, 11:21 AM
Hey @hoffeman this usually happens if you pass in the request object instead of passing in the response object in some function of ours which requires them as the input
it can also happen if you have already sent the response and then you trigger something that causes a header update from our side
h

hoffeman

07/04/2022, 11:22 AM
yes, it is weird since it only happens sometimes. Im thinking it could be when the client is using the refresh token
r

rp

07/04/2022, 11:23 AM
probably not, unless you have overriden the refresh API
it's most like that the response has already been sent
h

hoffeman

07/04/2022, 11:26 AM
true
im also using the SupertokensExceptionFilter from the guide so it should stop propagation if headers have been sent
r

rp

07/04/2022, 11:32 AM
yeaa.. maybe you can see which function call is causing this error?
h

hoffeman

07/05/2022, 9:57 AM
[Nest] 78 - 07/05/2022, 9:56:51 AM ERROR [ExceptionsHandler] Error while setting header with key: front-token and value: eyJ1aWQiOiJkYjZmYWVlNC0zNDU1LTRlYTYtODdjOS04N2M2NjA4MzA0YWYiLCJhdGUiOjE2NTcwMTg2MTExNTEsInVwIjp7InJvbGUiOiJBRE1JTiIsIm9yZ2FuaXphdGlvbklkIjoidGVzdCJ9fQ== rapid-api_1 | Error: Error while setting header with key: front-token and value: eyJ1aWQiOiJkYjZmYWVlNC0zNDU1LTRlYTYtODdjOS04N2M2NjA4MzA0YWYiLCJhdGUiOjE2NTcwMTg2MTExNTEsInVwIjp7InJvbGUiOiJBRE1JTiIsIm9yZ2FuaXphdGlvbklkIjoidGVzdCJ9fQ== rapid-api_1 | at Object.setHeaderForExpressLikeResponse (/usr/src/app/node_modules/supertokens-node/lib/build/framework/utils.js:236:15) rapid-api_1 | at ExpressResponse.setHeader (/usr/src/app/node_modules/supertokens-node/lib/build/framework/express/framework.js:111:21) rapid-api_1 | at Object.setFrontTokenInHeaders (/usr/src/app/node_modules/supertokens-node/lib/build/recipe/session/cookieAndHeaders.js:73:9) rapid-api_1 | at Object. (/usr/src/app/node_modules/supertokens-node/lib/build/recipe/session/recipeImplementation.js:216:44) rapid-api_1 | at Generator.next () rapid-api_1 | at fulfilled (/usr/src/app/node_modules/supertokens-node/lib/build/recipe/session/recipeImplementation.js:15:36) rapid-api_1 | at processTicksAndRejections (node:internal/process/task_queues:95:5)
this is the only stack trace i get..
i also tried disabling all exceptionfilters
r

rp

07/05/2022, 9:59 AM
Can you upload your code and share it on github?
h

hoffeman

07/05/2022, 9:59 AM
it seems to only happen after i while so im thinking it has something to do when it needs to refresh the token
yea sure, can I invite you? it is a private repo
r

rp

07/05/2022, 10:00 AM
deos this happen when calling the refresh API only?
yea. Invite me to id
rishabhpoddar is my github
h

hoffeman

07/05/2022, 10:00 AM
no it is actually a regular api request
r

rp

07/05/2022, 10:00 AM
@porcellus can help here too
h

hoffeman

07/05/2022, 10:02 AM
i have added you to the repo now
r

rp

07/05/2022, 10:02 AM
ok thanks
h

hoffeman

07/05/2022, 10:03 AM
ignore all the commit messages plz 🙂
r

rp

07/05/2022, 10:03 AM
haha
fair
h

hoffeman

07/05/2022, 10:03 AM
cloud-api/api/common/auth/
thats where the supertoken module is located
r

rp

07/05/2022, 10:03 AM
ok thanks
p

porcellus

07/05/2022, 10:03 AM
hi
so what I'd check is the kind of error that's caught and rethrown as the "error while setting header"
are you running this locally?
h

hoffeman

07/05/2022, 10:07 AM
yes
let me check
hmm do you have an idea how to check the kind of error in nest?
tried using a catch all but cant the error type
p

porcellus

07/05/2022, 10:13 AM
oh, I think the easiest way is to just edit
node_modules/supertokens-node/lib/build/framework/utils.js:236:15
🙂
h

hoffeman

07/05/2022, 10:27 AM
TypeError: res.getHeaders is not a function
thats what i initially though. express 4 uses res.set(key, value) for headers
could be that
oh or sorry
its the getHeaders
but that should be .get() in express 4
p

porcellus

07/05/2022, 10:29 AM
yep
r

rp

07/05/2022, 10:29 AM
we wrap the res object in supertokens to standardise the functions across different frameworks. In our wrapper, we have
getHeaders
as a function.
h

hoffeman

07/05/2022, 10:30 AM
ah ok. any idea how i can continue troubleshooting?
r

rp

07/05/2022, 10:34 AM
let us check
@kakashi_44 see here please
@hoffeman can you please open an issue about this on our github?
we will fix it right away
h

hoffeman

07/05/2022, 10:38 AM
sure
r

rp

07/05/2022, 10:38 AM
thanks
h

hoffeman

07/05/2022, 10:39 AM
if i relogin on the frontend it works again, it is only after being idle and then making a request this happens
any special guidelines i need to follow for the issue?
r

rp

07/05/2022, 10:42 AM
Not really, you can just describe it however you like
In the JS code you modified, can you print out the value of
res
? What does it print?
h

hoffeman

07/05/2022, 10:52 AM
i just reloggedin, probably have to wait a while before the error occurs again 🙂
but ill post here asap
r

rp

07/05/2022, 10:53 AM
right. Can you delete the access token from cookies and then make an API request?
h

hoffeman

07/05/2022, 10:53 AM
y
r

rp

07/05/2022, 10:53 AM
Maybe that will trigger the error
h

hoffeman

07/05/2022, 10:53 AM
nope got a more stuructured error "Access token has expired"
now i got it
not exactly the same though
r

rp

07/05/2022, 10:55 AM
ok. Great! Can you show me what the value of
res
is?
h

hoffeman

07/05/2022, 10:58 AM
there is almost the full res object
the console truncated the first part
if needed i could try to save it as a file
r

rp

07/05/2022, 11:01 AM
right. I am seeing it now
Can you show the full object please?
h

hoffeman

07/05/2022, 11:05 AM
ill try, i think i get a circular json error when JSON.stringiy the object
r

rp

07/05/2022, 11:06 AM
Can you try and log:
Copy code
console.log(res.getHeaders)
console.log(res.get)
h

hoffeman

07/05/2022, 11:07 AM
sure, but note that the error i get now after deleting the cookie is not happening in the same function
but it could probably be related
r

rp

07/05/2022, 11:08 AM
right.
h

hoffeman

07/05/2022, 11:09 AM
undefined [Function: header]
so getHeader and getHeaders is undefined
res.get is a function
r

rp

07/05/2022, 11:11 AM
ok thanks. This is helpful
h

hoffeman

07/05/2022, 11:13 AM
r

rp

07/05/2022, 11:15 AM
thank you!
Hey @hoffeman how can I run the server on my local machine?
h

hoffeman

07/05/2022, 9:02 PM
Hi sorry for late response. Just run npm run dev. Requires docker and docker-compose though
You might also need a dev-account.json in root dir. I think it will start with a dummy
r

rp

07/06/2022, 3:53 AM
Ok thanks
hey @hoffeman i tried to setup a new nestjs project similar to yours and it all works fine. Can we get on a call to debug this on your project?
You can pick a time here: https://supertokens.com/call-user
h

hoffeman

07/06/2022, 5:34 PM
Yes, i booked a time on friday. Did you succeed to start my project or a new scaffold nestjs?
r

rp

07/06/2022, 6:27 PM
Hey! I couldn't get the project you gave us to work, that's why i asked for a call - so we can debug it 🙂
h

hoffeman

07/07/2022, 1:14 PM
👍
n

nkshah2

07/08/2022, 8:47 AM
Hey @hoffeman, Just let us know when you're ready for the call
h

hoffeman

07/08/2022, 8:47 AM
yes 🙂
ok i think i can show you now 🙂
r

rp

07/08/2022, 8:57 AM
cool
h

hoffeman

07/08/2022, 8:57 AM
should we use the old meeting room?