{"_id":"@daveyplate/better-auth-capacitor","_rev":"2-91a812d6a1ed14d7fee9682fef475ec2","name":"@daveyplate/better-auth-capacitor","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@daveyplate/better-auth-capacitor","version":"0.0.1","keywords":["typescript"],"author":{"name":"daveycodez"},"license":"MIT","_id":"@daveyplate/better-auth-capacitor@0.0.1","maintainers":[{"name":"leakeddave","email":"leakeddave@me.com"}],"homepage":"https://github.com/daveyplate/better-auth-capacitor","dist":{"shasum":"8fe1e960dbbcbf79d56f5eda1e37ae2c1609939b","tarball":"https://registry.npmjs.org/@daveyplate/better-auth-capacitor/-/better-auth-capacitor-0.0.1.tgz","fileCount":23,"integrity":"sha512-h76cZK4w8OQG0oUD9QzEU6jlv08z+/LcE5PQxYE0Euks52Zc81JO16VnsG9Gln7kzUOwI+vRxNlaljt6nWDQhg==","signatures":[{"sig":"MEQCIG62OyEXGvkeDgGy//Lk5w1JSIDJ+lvon3EM2yjdQANGAiA7aN+k9CxXuWiHbazOq1jfJQ46MXmGobMpM1WCbgCEhw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":20733},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"./react":{"import":{"types":"./dist/react.d.ts","default":"./dist/react.js"},"require":{"types":"./dist/react.d.cts","default":"./dist/react.cjs"}}},"gitHead":"360a68466bf660a18727869a5ee58a78e63613c1","scripts":{"dev":"tsc-watch --onSuccess 'biome check --fix'","build":"tsup --clean --dts","prepublishOnly":"rm -rf dist && tsup --clean --dts"},"_npmUser":{"name":"leakeddave","email":"leakeddave@me.com"},"_npmVersion":"11.0.0","description":"Capacitor helpers for Better Auth OAuth, Magic Link, etc using Universal Links","directories":{},"_nodeVersion":"22.11.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.8.1","devDependencies":{"tsx":"^4.19.3","tsup":"^8.4.0","react":"^19.1.0","turbo":"^2.5.0","react-dom":"^19.1.0","tsc-watch":"^6.2.1","typescript":"^5.8.3","@types/node":"^22.14.1","better-auth":">=1.2.7","@types/react":"^19.1.2","@capacitor/app":">=7.0.0","@types/react-dom":"^19.1.2","esbuild-plugin-preserve-directives":"^0.0.11"},"peerDependencies":{"react":">=18.0.0","react-dom":">=18.0.0"},"_npmOperationalInternal":{"tmp":"tmp/better-auth-capacitor_0.0.1_1746350504876_0.14693189871928958","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-05-04T09:21:44.770Z","modified":"2025-11-21T03:12:59.245Z","0.0.1":"2025-05-04T09:21:45.055Z"},"author":{"name":"daveycodez"},"license":"MIT","homepage":"https://github.com/daveyplate/better-auth-capacitor","keywords":["typescript"],"description":"Capacitor helpers for Better Auth OAuth, Magic Link, etc using Universal Links","maintainers":[{"email":"leakeddave@me.com","name":"leakeddave"},{"email":"daveycodez@gmail.com","name":"daveycodez"}],"readme":"# Better Auth Capacitor Plugin\n\nA client-side plugin for [Better Auth](https://better-auth.com) that provides seamless integration with [Capacitor](https://capacitorjs.com) applications, enabling OAuth and Magic Link authentication through Universal Links.\n\n## Installation\n\n```bash\n# npm\nnpm install @daveyplate/better-auth-capacitor\n\n# pnpm\npnpm add @daveyplate/better-auth-capacitor\n\n# yarn\nyarn add @daveyplate/better-auth-capacitor\n\n# bun\nbun add @daveyplate/better-auth-capacitor\n```\n\n## Prerequisites\n\nThis plugin requires:\n\n- A configured [Better Auth](https://better-auth.com) client\n- [Capacitor](https://capacitorjs.com) with the App plugin (`@capacitor/app`)\n- Properly configured Universal Links for iOS/Android\n\n## Client Setup\n\n### Option 1: Standard JavaScript/TypeScript Setup\n\n```typescript\nimport { setupBetterAuthCapacitor } from \"@daveyplate/better-auth-capacitor\";\nimport { authClient } from \"@/lib/auth-client\";\n\n// Initialize in your app's entry point\nconst cleanup = setupBetterAuthCapacitor({\n  authClient, // Your Better Auth client instance\n  debugLogs: false, // Optional: Enable debug logs\n  onRequest: (href) => {\n    console.log(\"Auth request:\", href);\n  },\n  onSuccess: (callbackURL) => {\n    console.log(\"Auth successful, callback URL:\", callbackURL);\n    // Handle successful authentication, refetch the session\n    if (callbackURL) {\n      window.location.href = callbackURL;\n    }\n  },\n  onError: (error) => {\n    console.error(\"Auth error:\", error);\n    // Handle authentication error\n  },\n});\n\n// Call cleanup when your app unmounts/closes to remove listeners\n// cleanup();\n```\n\n### Option 2: React Setup\n\n```typescript\nimport { useBetterAuthCapacitor } from \"@daveyplate/better-auth-capacitor/react\";\nimport { authClient } from \"@/lib/auth-client\";\n\nfunction App() {\n  const { isLoading, error } = useBetterAuthCapacitor({\n    authClient,\n    debugLogs: false,\n    onRequest: (href) => {\n      console.log(\"Auth request:\", href);\n    },\n    onSuccess: (callbackURL) => {\n      console.log(\"Auth successful\")\n      // Refetch the session\n\n      if (callbackURL) {\n        // Handle navigation\n        // e.g. router.push(callbackURL)\n      }\n    },\n    onError: (error) => {\n      console.error(\"Auth error:\", error);\n      // Show error notification\n    },\n  });\n\n  // You can use isLoading and error states in your UI\n  if (isLoading) return <div>Authenticating...</div>;\n  if (error) return <div>Error: {error.message}</div>;\n\n  return (\n    // Your app components\n  );\n}\n```\n\n## How It Works\n\nThis plugin enables seamless authentication in Capacitor apps by:\n\n1. **Handling Universal Links**: Listens for authentication redirects through your app's universal links.\n2. **Processing Auth Callbacks**: Automatically processes auth callback URLs and communicates with the Better Auth backend.\n3. **Managing Authentication State**: Provides hooks and callbacks to update your app's UI based on authentication status.\n\nThe plugin will:\n- Listen for `appUrlOpen` events\n- Check if the URL is a Better Auth callback\n- Make the necessary fetch request to complete the authentication\n- Invoke the appropriate callback based on success or failure\n\n## Configuration Options\n\n| Option | Type | Description |\n|--------|------|-------------|\n| `authClient` | `AuthClient` | **Required**. Your Better Auth client instance |\n| `debugLogs` | `boolean` | Optional. Enable verbose console logging for debugging |\n| `onRequest` | `(href: string) => void` | Optional. Called when an auth request is initiated |\n| `onSuccess` | `(callbackURL?: string \\| null) => void` | Optional. Called on successful authentication |\n| `onError` | `(error: FetchError) => void` | Optional. Called when authentication fails |\n\n## License\n\nMIT","readmeFilename":"README.md"}