{"_id":"tauri-plugin-clerk","_rev":"2-16c54df68ba3b1a948984cb94600e1da","name":"tauri-plugin-clerk","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"tauri-plugin-clerk","version":"0.1.0","keywords":["clerk","tauri","auth"],"author":{"name":"@Nipsuli"},"license":"MIT","_id":"tauri-plugin-clerk@0.1.0","maintainers":[{"name":"nipsuli","email":"n.p.ahonen@gmail.com"}],"homepage":"https://github.com/Nipsuli/tauri-plugin-clerk#readme","bugs":{"url":"https://github.com/Nipsuli/tauri-plugin-clerk/issues"},"dist":{"shasum":"1ff501013ee88c4e8b553c484e1374c28fd3cfc1","tarball":"https://registry.npmjs.org/tauri-plugin-clerk/-/tauri-plugin-clerk-0.1.0.tgz","fileCount":5,"integrity":"sha512-1BL0CCgM1+LiU6FnrCdfZ/SLHdeHMkK/5Hyu72whrfUQY6VHRK7mvfLfy8ewsGNW0FGjE1Z0V0lDrPj1ydTGsA==","signatures":[{"sig":"MEUCIGlGFVC91fLgEJgU4ujnszNfxx94m+a7AzfzdbpScRG8AiEA3xazAmhdCO7pXC6hf7aDsrAei+qrrlxQft6emhbbeBU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":25433},"main":"./dist-js/index.js","type":"module","types":"./dist-js/index.d.ts","module":"./dist-js/index.js","exports":{"types":"./dist-js/index.d.ts","import":"./dist-js/index.js"},"gitHead":"a685425481f7211f346c55a6492a72121b042921","scripts":{"build":"tsdown","checks":"run-p checks:*","dev:js":"tsdown --watch ./guest-js","format":"prettier --write \"guest-js/**/*.ts\"","pretest":"npm build","checks:lint":"oxlint guest-js","checks:types":"tsc --noEmit","checks:format":"prettier --check \"guest-js/**/*.ts\"","prepublishOnly":"npm run build"},"_npmUser":{"name":"nipsuli","email":"n.p.ahonen@gmail.com"},"repository":{"url":"git+https://github.com/Nipsuli/tauri-plugin-clerk.git","type":"git"},"_npmVersion":"11.6.0","description":"An unofficial Tauri SDK for Clerk","directories":{},"_nodeVersion":"24.8.0","dependencies":{"@clerk/types":"^4.92.0","@clerk/clerk-js":"^5.99.0","@tauri-apps/api":">=2.5.0","@tauri-apps/plugin-http":"^2.4.4"},"_hasShrinkwrap":false,"devDependencies":{"tslib":"^2.8.1","oxlint":"^1.23.0","tsdown":"^0.15.7","prettier":"^3.6.2","typescript":"^5.9.3","npm-run-all":"^4.1.5"},"_npmOperationalInternal":{"tmp":"tmp/tauri-plugin-clerk_0.1.0_1760654795181_0.9042537902697401","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"tauri-plugin-clerk","version":"0.1.1","author":{"name":"@Nipsuli"},"description":"An unofficial Tauri SDK for Clerk","keywords":["clerk","tauri","auth"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/Nipsuli/tauri-plugin-clerk.git"},"type":"module","types":"./dist-js/index.d.ts","main":"./dist-js/index.js","module":"./dist-js/index.js","exports":{"types":"./dist-js/index.d.ts","import":"./dist-js/index.js"},"scripts":{"build":"tsdown","dev:js":"tsdown --watch ./guest-js","prepublishOnly":"npm run build","pretest":"npm build","format":"prettier --write \"guest-js/**/*.ts\"","checks:format":"prettier --check \"guest-js/**/*.ts\"","checks:types":"tsc --noEmit","checks:lint":"oxlint guest-js","checks":"run-p checks:*"},"dependencies":{"@clerk/clerk-js":"^6.0.0","@clerk/shared":"^4.0.0","@tauri-apps/api":"^2.10.1","@tauri-apps/plugin-http":"^2.5.7"},"devDependencies":{"npm-run-all":"^4.1.5","oxlint":"^1.51.0","prettier":"^3.8.1","tsdown":"^0.15.12","tslib":"^2.8.1","typescript":"^5.9.3"},"_id":"tauri-plugin-clerk@0.1.1","gitHead":"ef3825b091883f3cb2e27b0157a255347bfd754b","bugs":{"url":"https://github.com/Nipsuli/tauri-plugin-clerk/issues"},"homepage":"https://github.com/Nipsuli/tauri-plugin-clerk#readme","_nodeVersion":"24.7.0","_npmVersion":"11.5.1","dist":{"integrity":"sha512-YAfL9Qhe8Lo6BAjnj5hLdDYXAFBR5gpV4ukjYSwczZ/3/a9lMR/o86JQOZKBuxH3UKfzEvD8FWR3XFBYv9VB/A==","shasum":"484597433ae71d4d50542886d0a49c4499e90395","tarball":"https://registry.npmjs.org/tauri-plugin-clerk/-/tauri-plugin-clerk-0.1.1.tgz","fileCount":5,"unpackedSize":27028,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICNEeLPe8KXrXEmFhJLzQHaPA0BC4oGbtks5iE5gX/TyAiAB6hLddTaEOJpYsQfZYNu3N8T6IhJZiwMGym0v3IRRYw=="}]},"_npmUser":{"name":"nipsuli","email":"n.p.ahonen@gmail.com"},"directories":{},"maintainers":[{"name":"nipsuli","email":"n.p.ahonen@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tauri-plugin-clerk_0.1.1_1773601789230_0.0773720269588789"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-16T22:46:35.179Z","modified":"2026-03-15T19:09:49.519Z","0.1.0":"2025-10-16T22:46:35.360Z","0.1.1":"2026-03-15T19:09:49.419Z"},"bugs":{"url":"https://github.com/Nipsuli/tauri-plugin-clerk/issues"},"author":{"name":"@Nipsuli"},"license":"MIT","homepage":"https://github.com/Nipsuli/tauri-plugin-clerk#readme","keywords":["clerk","tauri","auth"],"repository":{"type":"git","url":"git+https://github.com/Nipsuli/tauri-plugin-clerk.git"},"description":"An unofficial Tauri SDK for Clerk","maintainers":[{"name":"nipsuli","email":"n.p.ahonen@gmail.com"}],"readme":"# Clerk Tauri SDK\n\nCommunity maintained Clerk SDK for Tauri apps.\n\nThere's also platform agnostic Rust implementations of\n[Clerk's Frontend API (FAPI)](https://github.com/Nipsuli/clerk-fapi-rs) and\n[Clerk's Backend API (BAPI)](https://github.com/DarrenBaldwin07/clerk-rs)\navailable.\n\nThis package is in use in production at [reconfigured](https://reconfigured.io/)\n\n## Usage\n\nInstall both the Rust and js packages:\n\nIn the `src-tauri` directory\n\n```bash\ncargo add tauri-plugin-clerk\n```\n\nIn the app directory\n\n```bash\nnpm install tauri-plugin-clerk\n```\n\nAdd `clerk:default` to the permissions. And ensure the `http` permissions allow\nconnecting to your Clerk host. Simple `src-tauri/capabilities/default.json`\n\n```json\n{\n  \"$schema\": \"../gen/schemas/desktop-schema.json\",\n  \"identifier\": \"default\",\n  \"description\": \"\",\n  \"windows\": [\"main\"],\n  \"permissions\": [\n    \"clerk:default\",\n    {\n      \"identifier\": \"http:default\",\n      \"allow\": [\n        {\n          \"url\": \"https://*\"\n        }\n      ]\n    }\n    ... rest of the permissions\n  ],\n}\n```\n\nInitialize the plugin on the tauri entrypoint\n\n```rs\n#[cfg_attr(mobile, tauri::mobile_entry_point)]\npub fn run() {\n    let clerk_publishable_key = todo!(\"Load the way you want\");\n\n    tauri::Builder::default()\n        // needed for the request routing\n        .plugin(tauri_plugin_http::init())\n        // Optional if one wants to persist the auth state\n        .plugin(tauri_plugin_store::Builder::new().build())\n        .plugin(\n            tauri_plugin_clerk::ClerkPluginBuilder::new()\n                .publishable_key(clerk_publishable_key)\n                // Optional if one wants to persist the auth state\n                .with_tauri_store()\n                .build(),\n        )\n        // All the other plugins etc\n        .run(tauri::generate_context!())\n        .expect(\"error while running tauri application\");\n}\n```\n\nExample minimal client with React\n\n```tsx\nimport type { Clerk } from \"@clerk/clerk-js\";\nimport { ClerkProvider } from \"@clerk/react\";\nimport { initClerk } from \"tauri-plugin-clerk\";\n\nexport const App = () => {\n  const clerkPromise = initClerk();\n  return (\n    <Suspense fallback={<div>loading...</div>}>\n      <AppWithClerk clerkPromise={clerkPromise} />\n    </Suspense>\n  );\n};\n\nconst AppLoaded = ({ clerkPromise }: { clerkPromise: Promise<Clerk> }) => {\n  const clerk = use(clerkPromise);\n  return (\n    <ClerkProvider publishableKey={clerk.publishableKey} Clerk={clerk}>\n      <ActualApp />\n    </ClerkProvider>\n  );\n};\n```\n\nSee examples for more\n\n## Core Idea\n\nThe Javascript side of Clerk is the one that orchestrates everything but the\nauth state is propagated to Rust side as well so one can get the current auth\nstate in rust code as well. The syncing of client state from rust side back to\njavascript is still in the works.\n\nOne can use the js side Clerk functionality almost as in browser environment and\nin combination of other Clerk frontend SDK's such as `@clerk/react`\n\nSome limitations:\n\n- OAuth flows do not work in the default signin component. Haven't figured out a\n  good way to do those in Tauri, one might be able to build custom auth flow for\n  that, haven't tested yet.\n- Magic links don't work, haven't figured out a way to make those work in Tauri\n- DomainOrProxy is not yet implemented\n\n## Notes\n\nDue to some limitations of Tauri platform:\n\n- Requires `tauri_plugin_http` to be initialized\n- This package patches `globalThis.fetch` to be able to route Clerk calls via\n  rust\n\n## Why this package works the way it does?\n\nAs tauri uses native webview (=browser) the first question easily is why is this\npackage needed? The reason why one cannot use the default Clerk web packages is\nhow web views on different platform deals with cookies. Example on mac cookies\ndo not work on custom domains such as Tauri uses. One way around this is to\npatch `document.cookies` but that leaves the authenticated state only on the\nclient side and would still require patching fetch calls to intercept cookies.\nAnother solution is to have the the authentication state fully on rust side and\nfor that there is [clerk-fapi-rs](https://crates.io/crates/clerk-fapi-rs) which\nworks well with Tauri in case one is building more rust heavy Tauri app.\n\nThe solution this package takes is to patch global fetch and pipe fetch calls\nthat have `x-tauri-fetch` header through\n[tauri-plugin-http](https://crates.io/crates/tauri-plugin-http) this is because\nof the limitations of the the API resulting in error if one just appends the JWT\ntoken in client side calls:\n\n```json\n{\n  \"errors\": [\n    {\n      \"message\": \"Setting both the 'Origin' and 'Authorization' headers is forbidden\",\n      \"long_message\": \"For security purposes, only one of the 'Origin' and 'Authorization' headers should be provided, but not both. In browser contexts, the 'Origin' header is set automatically by the browser. In native application contexts (e.g. mobile apps), set the 'Authorization' header.\",\n      \"code\": \"origin_authorization_headers_conflict\"\n    }\n  ],\n  \"clerk_trace_id\": \"...\"\n}\n```\n\nBy patching the global fetch to direct api calls through rust we can use the\nClerk javascript package as is and hook to the `onBeforeRequest` and\n`onAfterResponse` hooks similarly as in the Clerk expo package does. In addition\nthis package allows one to persist the Clerk session on disk to maintain the\nlogin state.\n\n## Contributing\n\nContributions in form of issues and prs are welcome.\n","readmeFilename":"README.md"}