Unexpected End of JSON Input on API Route
I am working through creating a OIDC workflow. I have a Astro site that sends the user to the Auth endpoint which handles the handshake with Google for Auth and through the
redirect_url
I send the browser back to the SolidStart App.
I have this file at src/routes/auth/callback.ts
that works in dev mode but not when deployed:
Locally on my machine it works just fine but when deployed I get a 500 Request error Unexpected end of JSON input
with the OIDC code in the URL bar: my.domain.com/auth/callback?code=eyJhbGci...
If I pull the code out and put it into jwt.io to validate, its valid and expected. I dont know where to go from here to debug further and would love some guidance on where to investigate and understand where my bug is.18 Replies
is the
VITE_AUTH_URL
env variable set on your deployment?It is, I validated by logging it to the console in aws cloudwatch.
okay, the errors says that the
response
doesn't return a json, can you console.log it before calling .json()?All the variables seem to be set as expected. I added a console.log statement right below the
if (response.ok)
so I can see it gets all the way there but it seems to fall over at the const { access_token} =
line.
Yeah, Are you saying to add a console.log(response) in the if (response.ok) {
statement?yes, just above .json()
Just added it, let me do a deploy since I cant replicate in dev mode
I added the "LOGGING RESPONSE` part to make it easier to find in the AWS console.
and what is the content of the body when you do response.text()?
Ill update and deploy. I did get a typescript error that the access_token does not exist on string.
Body is unusable: Body has already been read
from the web browser and this in aws logs:
I need to edit this later to remove my info:thinkies:
response.text() shouldn't return this error
you need to await response.text() afaik
and then you can see the plain response which isn't a json it seems
you can ignore the other error at the bottom, that's because you call text() and json() and both want to consume the body
Yeah, seems like it returns a jwt encoded response for the code.
I think the problem I am trying to understand is why does this work when running locally on my machine. Let me check something locally though
Yeah, running in dev mode, the original code works and sets the auth_token to
please watch out sharing your tokens like this xD
I don't know what could be the cause of this bth
Theres nothing sensitive 😅 just an email address
okay :)
and you're sure that the environment variable are the same?
other than that I don't know
Yeah they should be but I can add logging in to validate again against localhost. Auth resides in lambda at all times so it shouldnt change other than redirecting to localhost in dev or to the solidstart app when deployed.
I appreciate your help though! Ill keep poking at it and see what I can figure out, its been two days troubleshooting so I was starting to think it was something obvious I did.
I have to step away for a little (prob for the best to let the mind churn on it) but thank you again for taking time to help!
no problem!