Trying to make a request to my backend but getting...
# support-questions
p
Trying to make a request to my backend but getting back unauthorized. I understand cookies are sent automatically? I previously successfully received the cookies in the response headers of
signup/code/consume
. Also using
'Access-Control-Allow-Credentials': true
on my request to the backend. What am I missing? After receiving the cookies from
signup/code/consume
I should see the cookies on dev tools>storage>cookies, correct? because I don't. Btw, I'm using
fetch
, not
axios
r
Trying to make a request to my backend but getting back unauthorized. I understand cookies are sent automatically? I previously successfully received the cookies in the response headers of
signup/code/consume
. Also using
'Access-Control-Allow-Credentials': true
on my request to the backend. What am I missing? After receiving the cookies from
signup/code/consume
I should see the cookies on dev tools>storage>cookies, correct? because I don't. Btw, I'm using
fetch
, not
axios
Can I see the request headers of the API call?
No cookies are being sent. Nor is interception happening
What’s the domain you are querying? And what is the appInfo object set to on the frontend and backend?
p
I'm querying from my frontend at
https://localhost:3000/
my backend (FastAPI) at
https://acheron-api.herokuapp.com/
r
Https? And not http?
What’s ur appInfo object?
p
both https... I'm not doing anything to appInfo on the frontend
on the backend I'm loading standard values
from an .env...
r
So on the frontend, what’s your apiDomain value?
And what are the .env values for the above?
p
those are fine, if I take out the validation at the backend api I get the resposne
I think this is the culprit, but idk how to send them
r
Are you calling supertokens.init before using
fetch
? Are you using
node-fetch
or the browser's inbuilt fetch?
What are the response headers in the sign in API?
p
yes, and no. it's sveltekit's fetch.. but just normal fetch for this matter
r
I mean, are you importing fetch from somewhere and using that?
Cause i don't think that will work. On the client side, you should use
window.fetch
.
p
I'm not importing fetch.. I'm using the default one on a .js file
r
Hmmm
p
now not sure what I did but I'm no longer getting the sign response, recognize the reason for this error?
r
That’s probably an error in how you are sending email / sms. The callback function you implemented is throwing that error
p
yea I think I have it, 1 sec, rebuilding
r
Ok. This seems fine
p
now it's working, had a retard 'await' while requesting the email in the backend. See? I'm getting the cookies
but they are not 'sticking'
r
So two things: - The cookies are attached to the api domain, but you are viewing the website domain's cookie store. - Im sure that the interceeptors are not being applied to
fetch
and thats' why things are not working
p
ignore the 'token' there
r
In the
.then
of fetch, can you call
await supertokens.doesSessionExist()
?
And see what that prints out
p
I can't use it there, it says SuperTokens is undefined. that's a
api.js
utility
r
Right. Are you calling supertokens.init on the frontend?
p
yes.. I'm calling it on the layout file for all routes
r
So this fetch, is it called on server side or client side?
p
client side, on mount
r
Cause if it’s the client side, you can import supertokens from supertokens-website and call that function in the .then
p
SuperTokens is init'd client side, on mount
r
Right. So you should be able to call supertokens.doesSessionExist in the .then of the fetch?
p
it's returning false
tested it somewhere else
after signin and getting something like this
r
Are you sure that supertoeks.init is being called before calling fetch?
Maybe it would be a good idea to get on a call to debug this
p
yes I even tried to initing right before the fetch
happy to get on a call, I'm super lost with frontend dev and I think sveltekit, despite all its magic, might be making things harder
r
Yeaaaa. Fair. Can you please book a slot using the link on our site
On the landing page, you can find the link with “consult an expert”
p
yes, but damn the soonest is tmrw at 2pm
(local)
r
Well. Yeaaa.
p
will take that one, thanks 😄
took the one at my 5am
r
Oh wow.
7 Views