User story around on cookies + authentication #5337
Unanswered
Nickersoft
asked this question in
Q&A
Replies: 3 comments 7 replies
-
...does no one else have this problem? 😭 |
Beta Was this translation helpful? Give feedback.
4 replies
-
Solved. Override window.fetch Here's a React example but it can be adapted. import { isTauri } from "@tauri-apps/api/core"
import { fetch as tauriFetch } from "@tauri-apps/plugin-http"
useEffect(() => {
if (isTauri()) {
const originalFetch = window.fetch
window.fetch = async (...args) => {
const [input] = args
const href = (input as URL).href
if (href?.startsWith("http")) {
return tauriFetch(...args)
}
return originalFetch(...args)
}
return () => {
window.fetch = originalFetch
}
}
}, [])
``` |
Beta Was this translation helpful? Give feedback.
2 replies
-
Looks slick! Though after digging through the code I'm still curious how the session is actually being managed. I looked at Better Auth's docs (haven't used it before) and it seems to rely on setting session cookies, but I thought these kind of cookies won't work in Tauri?
Tyler Nickerson
…On Jun 1, 2025, 1:25 PM -0400, daveycodez ***@***.***>, wrote:
Better Auth. I made a package https://github.com/daveyplate/better-auth-tauri
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey folks,
I've been toying with the idea of porting my SvelteKit app to a Tauri app for some time now (while still keeping a version on the web), and am confused about the user story regarding cookies + network authentication in Tauri. I couldn't find any solid docs on it, and am curious how other people are managing their apps.
Right now user authentication in my app is very straightforward:
Secure
cookie specific to my app's domainHowever, in the world of Tauri, this approach seems to break down. Tauri apps run off
tauri://localhost
, which is neither aSecure
origin (from my understanding), or a valid domain name. AFAIK my cookies will never be set. There's also the issue of CORS, which I tried to disable by settingcsp
tonull
, but it didn't seem to work when I tried, plus it just feels wrong.I tried using the Tauri
http
module to circumvent it, but it's not compatible with SvelteKit'sfetch
signature (though I know this will be fixed by #5136). I tried using the store plugin, but its reliance onwindow
makes it impossible to run server-side, which breaks SvelteKit'sdev
server.Regardless, trying to balance both cookie-based and store-based authentication resulted in a ton of messy boilerplate as I tried detecting the environment the app was being run.
Anyway, I was surprised to see there is not a user story around this detailed in the Tauri docs. I'm curious how other people are managing similar setups.
Beta Was this translation helpful? Give feedback.
All reactions