#getServerSideProps not passing prop data to page component

30 messages · Page 1 of 1 (latest)

frigid haven
#

I'm trying to request data from a spreadsheet, parse it then send it over to my quiz page for rendering, I cannot get it to work whatsoever with me and whenever I access data from the quiz's props it ends up being undefined only in production and I'm not sure why. I can't even log the variables on the server because I can't access server logs. Any insight?

Minimal Quiz: https://hastebin.com/joteteyoza.lua
Quiz getServerSideProps: https://hastebin.com/reziruzuji.js
_app (inspired from https://codesandbox.io/s/ku82o): https://hastebin.com/wahowejeko.js

#

getServerSideProps not passing prop data to page component

silver kindle
#

Are you sure the fetching of the spread sheet works in production?

#

Is the env variable set?

#

How come you can’t access server logs?

#

If deploying to vercel, open the deployments page and there will be a functions tab with logs

#

They don’t persist however so you need to trigger the error while viewing the logs

frigid haven
#

Are you sure the fetching of the spread sheet works in production?
Unable to verify but it's worked across both dev/prod versions on localhost.

Is the env variable set?
Yes, even set it again multiple times to be sure to the point of copy pasting the key and variable individually.

How come you can’t access server logs?
Don't know how to whatsoever, I tried looking through the docs and couldn't find anything. Was hoping on some insight on that side of things especially as I've just been shooting in the dark for hours.

They don’t persist however so you need to trigger the error while viewing the logs
Did try, nothing ended up coming up. I'll try again and send a screengrab of my findings if you'd like?

#

Okay sweet, logs are working now but not sure what I changed. I'll start printing everything in getServerSideProps while it's working as before it wasn't for some reason. Would a 5xx error halt server-side logging?

#

It doesn't seem like I'm receiving any of my prints on the getServerSideProps function, would it be due to the fact that my application is set to do everything on /? Here's my vercel.json:

{
    "rewrites": [{ "destination": "/", "source": "/(.*)" }]
}
#

Okay so I've gotten a bit closer though I feel like I've backpedalled, this definitely helped me out and now I have my foot through the door at least.

The only thing stopping me now is the fact that I have a credentials.json file I need my application to read, FWIW it needs all of it as it comes from Google Cloud and despite my committing it to the private repo, Vercel can't seem to pick it up within it's directory. What should I do from here?

silver kindle
#

I think the credentials json file should be stored as a an env variable in vercel

#

Don’t commit credentials to git as a basic rule of thumb when it comes to security

frigid haven
#

I know, there's no justifying it here really though I'm not sure how I'd be able to set it up as an env variable. Do you mean the path or the individual values, because the file has about 8 different ones thanks to Google.

Here's how I was originally trying to pass the file in:

    let initialAuth = new google.auth.GoogleAuth({
        keyFile: "credentials.json",
        scopes: "https://www.googleapis.com/auth/spreadsheets",
    });
#

Do you know of an alternative approach?

#

Or should I just do it the painful way and setup every entry as an env value?

silver kindle
#

The entire credentials file is a Json string

#

It can be stored as a string in an env variable

#

And then when you load it

#

Do JSON.parse

#

To turn it back into a JavaScript object

#

Im pretty sure the google api should accept an object instead of just a path to a key file, consult the docs

frigid haven
#

It does yeah, docs agree.

frigid haven
#

I'll be able to take it from there, thanks so much for your time man. I've literally solved 2/3 of my total posts here solo and it's been what, 10h of work at once? Bless ya heart.

silver kindle
#

There is a downside though, vercel has a limit of 4kb across all the env variables in a project

#

So if you have a lot of env variables this may not be feasible

frigid haven
#

That's perfectly fine, I can't even hit 200b let alone 4000. 😆

silver kindle
#

But if it’s just a few, this will work splendidly

#

Awesome. Glad I could help. Good luck!