Get session call failing Safari

Hi, I’ve recently setup better auth with nextjs, using the drizzle adapter and nextCookie plugin. I wrote my own plugin for steam authentication (OpenID 2.0), which seems to be working good. However, one weird bug I’ve seen is that on safari, the get session call made when the user clicks my sites sign in button throws an error with status 0 and status text as an empty string. Any idea why this is happening? Thanks!
55 Replies
Perfect
PerfectOP5d ago
@bekacru said…
this is casue it can't reach the server. Either base url or you haven't properly forwarded localhost port
My baseURL is set properly, and I’m using the nextjs dev server url. But this is happening deployed too. https://rust.directory
Rust Directory
Your go-to resource for staying ahead in rust.
Perfect
PerfectOP5d ago
Perfect
PerfectOP5d ago
Perfect
PerfectOP5d ago
Seems like if I make a manual client action it skips the get-session route and works
No description
Perfect
PerfectOP5d ago
Where does the get-session call come from? is it some autoamic thing all client action that are inferred will call and do something with?
Perfect
PerfectOP5d ago
Maybe this is why from ai
No description
bekacru
bekacru3d ago
does authClient.getSession work also what error does it show in the console
Perfect
PerfectOP3d ago
Error is error code 0 status text empty string I haven’t tried get session but I think it works I’m away from computer for a bit, can check when I’m home too
Perfect
PerfectOP3d ago
Ok so @bekacru - I got a few questions for you: The plugin has two endpoints. One is /sign-in/steam and the other is /steam/callback. To show the session status in my ui, I have a component using the authClient.useSession() react hook. When the user is signed out, the button click will call authClient.signIn.steam() and then take the response (which contains a steam URL) and redirect to it. When the user is signed in, the button click will call authClient.signOut(). That is everything happening on the client side. 1. For sign in, the first thing that happens is the code in the plugin endpoint for /sign-in/steam. At the moment, it always generates a url using Open ID 2.0 and returns that in a JSON response. It seems like get-session is automatically called after the endpoint is completed. See screenshot for order. What is the purpose of this call, and why do you think it might only be failing on safari? 2. If the ui is not always in sync with session state, and the user tries to sign in again (when they already are), the plugin (at the moment) will still run the endpoint and generate a url for the user to go sign in at. Ideally we just update the ui and get the existing session. Should the change required for this live in the plugin or is the dev using the plugin responsible to handle that in their ui code? 3. Same question as number two, but for sign out ^ 4. Since email is required in better-auth, I am just using a placeholder <steam-id>@example.com email when setting up users, but do you have any better/recommended way to handle this? Thank you!
No description
Perfect
PerfectOP3d ago
@Gamers pinging you here since I know you were interested
Araloberry
Araloberry3d ago
have you checked CORS?
Perfect
PerfectOP2d ago
I havent, but what do you mean by checking it? There are no CORS errors I can see if that is what you mean. Also everything is on same domain (using nextjs for all).
Araloberry
Araloberry2d ago
Never mind if that's the case
Perfect
PerfectOP2d ago
damn any other ideas? @bekacru really hate to spam you here - just want to bump one more time if you get a chance to look at message I sent above. Been a few days and I am out of ideas :/
Araloberry
Araloberry2d ago
Does safari spit out any logs
Perfect
PerfectOP2d ago
Nope, just the error when useSession hook, which is an object with error code 0 and error status as empty string "Load Error" in nextjs
Araloberry
Araloberry2d ago
I feel like this has to do with safari’s tracking prevention If it’s working with any other browsers
Perfect
PerfectOP2d ago
yeah chrome works fine https://rust.directory - if you have safari you can see it live here
Araloberry
Araloberry2d ago
Works fine on my mobile safari
Perfect
PerfectOP2d ago
https://discord.com/channels/1288403910284935179/1365363073061486653/1365363940145758248 this is not happening for you? It happens on both mobile and macbook safari for me every time (private window as well to rule anything weird out, default settings)
Araloberry
Araloberry2d ago
Not at all
Perfect
PerfectOP2d ago
it just happened to me few seconds ago what the hell Can you send a screen recording? is there a setting you might have turned off to reduce the protections or something maybe? I am also not sure the call thats failing really matters since the user is actively being redirected when its being made. So it has no impact but I would have to change route name (/sign-in automatically does it) or write custom client action in plugin maybe?
Araloberry
Araloberry2d ago
check dm not sure what does your safari network ssys
Perfect
PerfectOP2d ago
its failing for you in the video you sent me see the flash of "Something went wrong" while it redirects
Araloberry
Araloberry2d ago
well it doesnt fail according to network log it doesnt seem to be issue with better auth
Perfect
PerfectOP2d ago
it is failing in logs for me, let me get log
Perfect
PerfectOP2d ago
No description
Perfect
PerfectOP2d ago
No description
Araloberry
Araloberry2d ago
can't really know much from SS one possible reason I can think of is that Safari is handling the redirect and the getSession call differently than other browsers. It having no status and returning 0 likely means that the call was aborted/cancelled In Chrome/Firefox, the background getSession request might complete before navigation in safari, it probably doesnt which then leads to browser aborting the request let me try something
Perfect
PerfectOP2d ago
Hmm yeah didnt think of that actually
Araloberry
Araloberry2d ago
try adding short delay before redirecting to Steam auth page if user is using safari I think it will solve most of the issues here
Perfect
PerfectOP2d ago
Ill try doing a long delay and see if it fixes it first
Araloberry
Araloberry2d ago
yup let me know how it goes btw your implementation is pretty interesting I've been trying to comeup with my own plugin for Steam too but I was too lazy to get it working please ping me if you managed to fix it
Perfect
PerfectOP2d ago
it seems to have fixed it locally so far I did 10 seconds
Araloberry
Araloberry2d ago
100ms is enough
Perfect
PerfectOP2d ago
no errors and get session finishes
Araloberry
Araloberry2d ago
yes good
Perfect
PerfectOP2d ago
This feels like a duct tape solution right?
Araloberry
Araloberry2d ago
uh no it's only solution issue is more with safari not better auth
Perfect
PerfectOP2d ago
Why does this call even get made
Araloberry
Araloberry2d ago
unless better auth redesign their session system not sure
Perfect
PerfectOP2d ago
I can disable it if I write a manual client action That just handles the steam url fetch And get session should be made before to see if they already have a session Seems backwards and I dont see why it happens after, only makes sense for auth that does not do redirects (email password or something)
Araloberry
Araloberry2d ago
I think it's designed to refresh the client's session state after authentication operations
Perfect
PerfectOP2d ago
right
Araloberry
Araloberry2d ago
probably best to ask bekacru
Perfect
PerfectOP2d ago
So in this case, I guess its not needced
Araloberry
Araloberry2d ago
it's just internal design I guess
Perfect
PerfectOP2d ago
Yeah I have been trying to get a hold of him, but he has been busy it seems fingers crossed he reads this 🙂 will try this other idea I have and let you know how it goes
Araloberry
Araloberry2d ago
alright @Perfect I have quick question. Is there specific reason you are using Better Auth if you are only using Steam as provider?
Perfect
PerfectOP2d ago
would you just recommend rolling my own completely, like session management and all I could but tbh wanted to try better auth lol
Araloberry
Araloberry2d ago
well I used passportjs https://www.passportjs.org/packages/passport-steam/ when I implemented one year ago. but tbh Steam auth itself is dumpster fire anywhere so I'm still not sure why they don't support oauth in 2025 using openid as only method is just crazy
Perfect
PerfectOP2d ago
Yeah I mean same idea, better auth still very helpful yeah thats what I hear I guess also good for future extensibility
Araloberry
Araloberry2d ago
Definitely If you have plan to use other providers in future
Perfect
PerfectOP15h ago
@bekacru bumping, thanks
Araloberry
Araloberry6h ago
How did this go

Did you find this page helpful?