Troubleshooting login error when starting a new Sanity project
48 replies
Last updated: Feb 26, 2023
R
any ideas why a in studio vision would follow the reference correctly while from the webapp, the reference doesn't get followed instead returns null?
Feb 26, 2023, 1:58 AM
A
Are you on the same dataset in vision and in your webapp?
Feb 26, 2023, 1:59 AM
R
yes!
Feb 26, 2023, 2:00 AM
A
Can you show me how you're trying to resolve the reference in your webapp?
Feb 26, 2023, 2:01 AM
A
you might be omitting
._reffrom the object chain
Feb 26, 2023, 2:01 AM
R
*[_type == "home"][0]{ _id, footer, name, showcaseExhibitions[]->, title, overview, header, subheader }
Feb 26, 2023, 2:02 AM
R
when i output the fetch() it just returns an array of null
Feb 26, 2023, 2:02 AM
A
So no documents are matching to
"home"?
Feb 26, 2023, 2:03 AM
R
{ _id: '2afb8db4-b79e-4056-b779-7b3f4c44fd98', footer: null, header: 'HEADER', name: null, overview: 'DESCRIPTION', showcaseExhibitions: [ null ], subheader: [ { _key: '072703d67f11', _type: 'block', children: [Array], markDefs: [], style: 'normal' } ], title: 'Home' }
Feb 26, 2023, 2:04 AM
R
if i get rid of the
->it returns the reference object
Feb 26, 2023, 2:04 AM
A
try
showcaseExhibitions._ref
Feb 26, 2023, 2:05 AM
A
no nvm that will jsut be the reference id
Feb 26, 2023, 2:05 AM
A
I think you're misusing the
->there. Here's an example of how im using it
Feb 26, 2023, 2:06 AM
A
if its not pointing to something then it makes sense that you're getting null
Feb 26, 2023, 2:06 AM
R
but it works vision
Feb 26, 2023, 2:07 AM
R
and returns a result
Feb 26, 2023, 2:07 AM
A
vision uses GQL for queries no?
Feb 26, 2023, 2:07 AM
A
GROQ is different
Feb 26, 2023, 2:07 AM
R
don't think so..i paste in the same query into vision and it gives me the result i expect
Feb 26, 2023, 2:09 AM
A
that's odd. there must be some context vision has that the Sanity client doesnt
Feb 26, 2023, 2:10 AM
A
maybe try specifying the fields you want to pull from
showcaseExhibitions
Feb 26, 2023, 2:10 AM
R
yeah..i start being super specific and then pulled back
Feb 26, 2023, 2:11 AM
R
wonder if there's some web setting..or if there's a way to turn on debugging so that i can diagnose what URL it's trying to hit
Feb 26, 2023, 2:12 AM
A
you can check your network tab in the devtools on the webapp
Feb 26, 2023, 2:12 AM
A
and see where the request is heading
Feb 26, 2023, 2:12 AM
R
yeah unfortunately next.js is doing is server side
Feb 26, 2023, 2:15 AM
A
i guess try making the request from client side
Feb 26, 2023, 2:17 AM
R
ugh my head hurts..looks like it is using the right URL. And when i copy and paste the URL it actually is the correct data.
Feb 26, 2023, 2:31 AM
R
but it seems that after fetching it it is disregarding it? do you know if fetch() is actually looking at any types?
Feb 26, 2023, 2:33 AM
R
actually the same URL when copy and pasted into the browser returns a result..but from executed from the app it doesn't
Feb 26, 2023, 2:37 AM
R
one query is 9ms the other one is 14ms
Feb 26, 2023, 2:37 AM
A
very weird, sounds like a bug
Feb 26, 2023, 2:39 AM
R
wondering it's something to do with CORS
Feb 26, 2023, 2:42 AM
R
that would be the only thing that is different
Feb 26, 2023, 2:42 AM
A
If CORS were an issue would you not be getting an error in your console about it?
Feb 26, 2023, 2:43 AM
R
yeah that's valid..something is happening on the sanity level it seems
Feb 26, 2023, 2:44 AM
A
Oof thats annoying
Feb 26, 2023, 2:45 AM
A
you should open an issue on github
Feb 26, 2023, 2:45 AM
R
okay...so in incognito mode i am getting the reference not being followed
Feb 26, 2023, 3:01 AM
R
so b/c i have logged in via studio..it's following them when i hit it directly
Feb 26, 2023, 3:01 AM
A
so its an auth issue?
Feb 26, 2023, 3:02 AM
R
so basically it seems like references don't get followed unless you are logged in? or use an auth token
Feb 26, 2023, 3:02 AM
R
yeah..will force a token in and see
Feb 26, 2023, 3:02 AM
A
i guess that makes sense
Feb 26, 2023, 3:02 AM
R
🤦‍♂️ yeah..when i force a token in it works..
Feb 26, 2023, 3:04 AM
R
i think this template i am using doesn't force the token unless in preview mode
Feb 26, 2023, 3:04 AM
A
well shit good job figuring it out!
Feb 26, 2023, 3:04 AM
R
ha..thanks for the suggestions and moral support
Feb 26, 2023, 3:09 AM
A
anytime 🙂
Feb 26, 2023, 3:10 AM
Sanity.io – build remarkable experiences at scale
Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.