Hello guy ! Small question for you, we are using t...
# support-questions-legacy
r
Hello guy ! Small question for you, we are using the supertokens-web-js library and I noticed that when we call the
createCode
function it's seems to also call the
session/refresh
do you know why ? Many thanks.
r
Hey. Which recipe are you using?
r
passwordless
r
Hmm. That function doesn’t call the refresh api at all
What’s the contents of the cookie store on the frontend?
r
there is no cookie it's on a fresh private session
r
Right. So the refresh is called once per new visitor to check initially if a session exists or not
But after that, it shouldn’t be called again unless the user logs in and their access token has expired
So it’s not really related to createCode function call
r
so why do I see the refresh call every time I start a new session and exactly the moment I call the createCode ?
r
So when the refresh api is called, and it returns a 401, is there anything that’s stored in the cookies?
you should see a cookie with the name
st-last-access-token-update
stored
r
yes indeed
r
right, and then if you just simply reload the page, do you see a call to the refresh API again?
r
no
But I mean why when I start a new private session I see the call to refresh after the createCode ?
r
yea that's odd. That call should happen whenever you check if a session exists and if it's a new private window
it's not related to createCode really.
but if you are making your own UI, it really also depends on when you call the function.
r
and is there a way to prevent this refresh call of we don't have the st-access-token in the cookie ?
r
there is. You can override the refresh function on the frontend. But if you do that, it may mess up our frontend SDKs logic - so be careful.
r
oh ok I'm not going to touch it now then but I would to prevent this not needed calls to our API
r
well, it's there for a reason.
but it should happen just once per private session
r
Ok thanks and for my curiosity what is the reason to try to refresh the session is the user is not logged in ?
r
cause the frontend needs to know if a session exists. Now normally, you could do that by checking if the right cookies exist on the frontend, but in browsers like safari, those cookies are auto cleared after 7 days of inactivity - so the only reliable way to know if a session exists is by checking if httpOnly cookies exists, which only the backend can check
r
Alright
thanks for the explanation
4 Views