oauth proxy + expo not working

Heya, migrated to better-auth from next-auth and ran into some issues with the oauth proxy. Worked through those but now I'm struggling getting it to play nice with Expo. I think it has to do with the multiple levels of redirects and each plugin writing the same query param, causing the former plugin to lose data in the roundtrip. Everything works fine on their own. Just using the oauth proxy i have working auth for prod, preview and dev on the web. And if i remove the oauth proxy i have working auth for prod and dev as well as on native, but not preview deployments. Anyone tackled this yet? Will play around and see if i can fix the expo client and/or the oauth proxy but just thought I'd raise it here to see if there's some prior art.
28 Replies
bekacru
bekacru3mo ago
I can see how it might easily conflict, especially since both try to catch the callback and change where it redirects. My simple guess is to try changing the plugin order so the OAuth proxy comes before the Expo plugin. But I haven’t tested preview deps with Expo. Let me know if you find the issue, if not, I’ll dig into it tonight.
julius
juliusOP3mo ago
tried both orders, no difference. this is the config: https://github.com/t3-oss/create-t3-turbo/blob/main/packages/auth/src/index.ts haven't had time to dig in yet though, might have some tomorrow
bekacru
bekacru3mo ago
@julius let me know if the pr version fixes the issue npm i https://pkg.pr.new/better-auth/better-auth@5d1960c
julius
juliusOP3mo ago
unfortuantely not :/ trying a clean build now in case it's cached some of the old version
julius
juliusOP3mo ago
nope :/
bekacru
bekacru3mo ago
I dont think this is the right patch basically, it should skip OAuth proxy plugin for expo since the expo plugin already kind of handles that npm i https://pkg.pr.new/better-auth/better-auth@a45492f this version should have the patch I'll check it from my side with the create t3 repo but it's working in my sample project
julius
juliusOP3mo ago
ah great. Does that also have the fix for http/https proxy? still not abel to get it working with this:
overrides:
better-auth: https://pkg.pr.new/better-auth/better-auth@a45492f
"@better-auth/expo": https://pkg.pr.new/better-auth/better-auth/@better-auth/expo@a45492f
overrides:
better-auth: https://pkg.pr.new/better-auth/better-auth@a45492f
"@better-auth/expo": https://pkg.pr.new/better-auth/better-auth/@better-auth/expo@a45492f
i'm getting sent back to turbo.t3.gg so it's still proxying something
julius
juliusOP3mo ago
beacuase i have this set
No description
bekacru
bekacru3mo ago
this is correct. It should redirect here first and when the oAuth flow finishes, it should redirect back to the mobile app instead. I'll try it with the t3 repo today
julius
juliusOP3mo ago
Did it work for you?
bekacru
bekacru3mo ago
yes, the proxy to the production url should still happen. But once the callback finishes, it should redirect directly to expo instead of going back to the original server to set cookies (that's the fix). Also, make sure you're using the same db and secret between dev and prod if you're testing this in a dev environment - same for preview.
julius
juliusOP3mo ago
Also, make sure you're using the same db and secret between dev and prod if you're testing this in a dev environment - same for preview.
Yea that I have. Let me try it again. Did you run it from main on the t3-turbo repo or your fork?
bekacru
bekacru3mo ago
from t3-turbo repo what error are you getting?
julius
juliusOP3mo ago
no error, just didn't get signed in let me try again, is this released now in 1.2.9?
julius
juliusOP3mo ago
julius
juliusOP3mo ago
that is 1.2.9 pushed to prod and local
bekacru
bekacru3mo ago
oh can you try const cookies = authClient.getCookie(); to see if the cookies are being stored
julius
juliusOP3mo ago
whereever?
bekacru
bekacru3mo ago
yeah
julius
juliusOP3mo ago
yea it is
No description
bekacru
bekacru3mo ago
okay I think the issue is __secure
julius
juliusOP3mo ago
yea feels like it if we're skipping proxy we don't get that .replace we fixed earlier?
bekacru
bekacru3mo ago
yeah, it'll be skipped. could you try forcing the auth server to use secure
advanced: {
useSecureCookies: true
}
advanced: {
useSecureCookies: true
}
add this on the auth.ts file
julius
juliusOP3mo ago
yup works
No description
bekacru
bekacru3mo ago
okay, so since we bypass the OAuth proxy, we lose access to the preview url, so we can’t perform the replacement in the expo plugin. I’ll think of a more proper way to handle this. In the meantime, I’ll open a PR on t3 turbo to make it work without secure cookies in the browser, and still using secure cookies for expo
julius
juliusOP3mo ago
can also use next dev --experimental-https and use secure everywhere i wish there was a laravel herd lite for node js so we could easily have local domains with ssl and everything... might need to go build something 😅
bekacru
bekacru3mo ago
yeah that's also an option

Did you find this page helpful?