@onmax/nuxt-better-auth 0.0.2-alpha.9 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +57 -17
  2. package/dist/module.d.mts +28 -1
  3. package/dist/module.json +3 -3
  4. package/dist/module.mjs +1258 -351
  5. package/dist/runtime/app/components/BetterAuthState.d.vue.ts +4 -4
  6. package/dist/runtime/app/components/BetterAuthState.vue +1 -0
  7. package/dist/runtime/app/components/BetterAuthState.vue.d.ts +4 -4
  8. package/dist/runtime/app/composables/runWithSessionRefresh.d.ts +1 -0
  9. package/dist/runtime/app/composables/runWithSessionRefresh.js +12 -0
  10. package/dist/runtime/app/composables/useAction.d.ts +2 -0
  11. package/dist/runtime/app/composables/useAction.js +6 -0
  12. package/dist/runtime/app/composables/useAuthAsyncData.d.ts +6 -0
  13. package/dist/runtime/app/composables/useAuthAsyncData.js +16 -0
  14. package/dist/runtime/app/composables/useAuthClient.d.ts +9 -0
  15. package/dist/runtime/app/composables/useAuthClient.js +34 -0
  16. package/dist/runtime/app/composables/useAuthClientAction.d.ts +3 -0
  17. package/dist/runtime/app/composables/useAuthClientAction.js +15 -0
  18. package/dist/runtime/app/composables/useAuthRequestFetch.d.ts +11 -0
  19. package/dist/runtime/app/composables/useAuthRequestFetch.js +4 -0
  20. package/dist/runtime/app/composables/useSignIn.d.ts +16 -0
  21. package/dist/runtime/app/composables/useSignIn.js +8 -0
  22. package/dist/runtime/app/composables/useSignUp.d.ts +5 -0
  23. package/dist/runtime/app/composables/useSignUp.js +8 -0
  24. package/dist/runtime/app/composables/useUserSession.d.ts +6 -5
  25. package/dist/runtime/app/composables/useUserSession.js +189 -100
  26. package/dist/runtime/app/composables/useUserSessionState.d.ts +3 -0
  27. package/dist/runtime/app/composables/useUserSessionState.js +4 -0
  28. package/dist/runtime/app/internal/auth-action-error.d.ts +3 -0
  29. package/dist/runtime/app/internal/auth-action-error.js +33 -0
  30. package/dist/runtime/app/internal/auth-action-handles.d.ts +21 -0
  31. package/dist/runtime/app/internal/auth-action-handles.js +105 -0
  32. package/dist/runtime/app/internal/redirect-helpers.d.ts +4 -0
  33. package/dist/runtime/app/internal/redirect-helpers.js +37 -0
  34. package/dist/runtime/app/internal/session-fetch.d.ts +12 -0
  35. package/dist/runtime/app/internal/session-fetch.js +56 -0
  36. package/dist/runtime/app/internal/utils.d.ts +1 -0
  37. package/dist/runtime/app/internal/utils.js +3 -0
  38. package/dist/runtime/app/internal/vue-safe-auth-proxy.d.ts +3 -0
  39. package/dist/runtime/app/internal/vue-safe-auth-proxy.js +68 -0
  40. package/dist/runtime/app/internal/wrap-auth-method.d.ts +18 -0
  41. package/dist/runtime/app/internal/wrap-auth-method.js +69 -0
  42. package/dist/runtime/app/middleware/auth.global.js +80 -15
  43. package/dist/runtime/app/pages/__better-auth-devtools.vue +293 -339
  44. package/dist/runtime/composables.d.ts +12 -0
  45. package/dist/runtime/composables.js +10 -0
  46. package/dist/runtime/config.d.ts +69 -15
  47. package/dist/runtime/config.js +9 -2
  48. package/dist/runtime/internal/auth-route-rules.d.ts +1 -0
  49. package/dist/runtime/internal/auth-route-rules.js +24 -0
  50. package/dist/runtime/server/api/_better-auth/_schema.d.ts +1 -5
  51. package/dist/runtime/server/api/_better-auth/_schema.js +2 -1
  52. package/dist/runtime/server/api/_better-auth/accounts.get.d.ts +2 -2
  53. package/dist/runtime/server/api/_better-auth/accounts.get.js +3 -2
  54. package/dist/runtime/server/api/_better-auth/config.get.d.ts +9 -3
  55. package/dist/runtime/server/api/_better-auth/config.get.js +18 -6
  56. package/dist/runtime/server/api/_better-auth/sessions.delete.js +3 -2
  57. package/dist/runtime/server/api/_better-auth/sessions.get.d.ts +5 -3
  58. package/dist/runtime/server/api/_better-auth/sessions.get.js +3 -2
  59. package/dist/runtime/server/api/_better-auth/users.get.d.ts +2 -2
  60. package/dist/runtime/server/api/_better-auth/users.get.js +3 -2
  61. package/dist/runtime/server/api/auth/[...all].js +1 -1
  62. package/dist/runtime/server/middleware/route-access.js +4 -2
  63. package/dist/runtime/server/tsconfig.json +9 -1
  64. package/dist/runtime/server/utils/auth.d.ts +16 -8
  65. package/dist/runtime/server/utils/auth.js +229 -23
  66. package/dist/runtime/server/utils/custom-secondary-storage.d.ts +6 -0
  67. package/dist/runtime/server/utils/custom-secondary-storage.js +8 -0
  68. package/dist/runtime/server/utils/session.d.ts +7 -8
  69. package/dist/runtime/server/utils/session.js +256 -5
  70. package/dist/runtime/server/virtual-modules.d.ts +27 -0
  71. package/dist/runtime/types/augment.d.ts +18 -4
  72. package/dist/runtime/types.d.ts +12 -13
  73. package/dist/types.d.mts +1 -1
  74. package/package.json +53 -47
package/README.md CHANGED
@@ -1,27 +1,67 @@
1
- <p align="center">
2
- <img src="https://raw.githubusercontent.com/onmax/nuxt-better-auth/main/.github/og.png" alt="Nuxt Better Auth" width="100%">
3
- <br>
4
- <sub>Designed by <a href="https://github.com/HugoRCD">HugoRCD</a></sub>
5
- </p>
1
+ # `@onmax/nuxt-better-auth`
6
2
 
7
- <h1 align="center">@onmax/nuxt-better-auth</h1>
3
+ Nuxt module for [Better Auth](https://better-auth.com) with Nuxt-native route protection, SSR-safe session access, auto-imported helpers, and optional NuxtHub-backed schema generation.
8
4
 
9
- <p align="center">Nuxt module for <a href="https://better-auth.com">Better Auth</a></p>
5
+ ## Who this is for
10
6
 
11
- <p align="center">
12
- <a href="https://npmjs.com/package/@onmax/nuxt-better-auth"><img src="https://img.shields.io/npm/v/@onmax/nuxt-better-auth/latest.svg?style=flat&colorA=020420&colorB=00DC82" alt="npm version"></a>
13
- <a href="https://npm.chart.dev/@onmax/nuxt-better-auth"><img src="https://img.shields.io/npm/dm/@onmax/nuxt-better-auth.svg?style=flat&colorA=020420&colorB=00DC82" alt="npm downloads"></a>
14
- <a href="https://npmjs.com/package/@onmax/nuxt-better-auth"><img src="https://img.shields.io/npm/l/@onmax/nuxt-better-auth.svg?style=flat&colorA=020420&colorB=00DC82" alt="License"></a>
15
- <a href="https://nuxt.com"><img src="https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js" alt="Nuxt"></a>
16
- </p>
7
+ Use this module if you want Better Auth in a Nuxt 4 app and you want the Nuxt-specific pieces handled for you:
17
8
 
18
- > [!WARNING]
19
- > This library is a work in progress and not ready for production use.
9
+ - `useUserSession()` for reactive auth state
10
+ - `requireUserSession(event)` and related server helpers
11
+ - route protection through `routeRules` and `definePageMeta({ auth })`
12
+ - generated `server/auth.config.ts` and `app/auth.config.ts`
13
+ - optional NuxtHub database integration and schema generation
14
+
15
+ ## Install the module
16
+
17
+ For the fastest path in a Nuxt 4 app:
18
+
19
+ ```bash
20
+ npx nuxi module add @onmax/nuxt-better-auth
21
+ ```
22
+
23
+ Then create or confirm these files:
24
+
25
+ - `server/auth.config.ts`
26
+ - `app/auth.config.ts`
27
+ - `.env` with `NUXT_BETTER_AUTH_SECRET`
28
+
29
+ For the full setup flow, follow the [installation guide](https://better-auth.nuxt.dev/getting-started/installation).
30
+
31
+ ## Choose your setup path
32
+
33
+ - Use [NuxtHub integration](https://better-auth.nuxt.dev/integrations/nuxthub) if you want the shortest path to database-backed auth.
34
+ - Use [custom database setup](https://better-auth.nuxt.dev/guides/custom-database) if you already have your own database stack.
35
+ - Use [external auth backend](https://better-auth.nuxt.dev/guides/external-auth-backend) if Better Auth runs in a separate service.
36
+ - Use [database-less mode](https://better-auth.nuxt.dev/guides/database-less-mode) for stateless or OAuth-first setups with clear tradeoffs.
20
37
 
21
38
  ## Documentation
22
39
 
23
- **[nuxt-better-auth.onmax.me](https://nuxt-better-auth.onmax.me/)**
40
+ The documentation site is at [better-auth.nuxt.dev](https://better-auth.nuxt.dev).
41
+
42
+ Recommended reading order:
43
+
44
+ 1. [Quickstart](https://better-auth.nuxt.dev/getting-started)
45
+ 2. [Installation](https://better-auth.nuxt.dev/getting-started/installation)
46
+ 3. [Configuration](https://better-auth.nuxt.dev/getting-started/configuration)
47
+ 4. [Client setup](https://better-auth.nuxt.dev/getting-started/client-setup)
48
+ 5. [Route protection](https://better-auth.nuxt.dev/core-concepts/route-protection)
49
+
50
+ ## Development
51
+
52
+ ```bash
53
+ pnpm install
54
+ pnpm dev:docs
55
+ ```
56
+
57
+ Useful commands:
58
+
59
+ - `pnpm dev` to run the playground
60
+ - `pnpm dev:docs` to run the docs site
61
+ - `pnpm lint` to lint the repo
62
+ - `pnpm test` to run the test suite
63
+ - `pnpm build:docs` to build the docs site
24
64
 
25
65
  ## License
26
66
 
27
- MIT
67
+ [MIT](https://github.com/nuxt-modules/better-auth/blob/main/LICENSE)
package/dist/module.d.mts CHANGED
@@ -1,9 +1,31 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { Nuxt } from '@nuxt/schema';
2
3
  import { BetterAuthModuleOptions } from '../dist/runtime/config.js';
3
4
  export { BetterAuthModuleOptions, defineClientAuth, defineServerAuth } from '../dist/runtime/config.js';
4
5
  import { BetterAuthOptions } from 'better-auth';
5
- export { Auth, AuthMeta, AuthMode, AuthRouteRules, AuthSession, AuthUser, InferSession, InferUser, RequireSessionOptions, ServerAuthContext, UserMatch } from '../dist/runtime/types.js';
6
+ export { AppSession, Auth, AuthActionError, AuthMeta, AuthMode, AuthRouteRules, AuthSession, AuthSocialProviderId, AuthUser, InferSession, InferUser, RequireSessionOptions, ServerAuthContext, UserMatch } from '../dist/runtime/types.js';
6
7
 
8
+ type DbDialect = 'sqlite' | 'postgresql' | 'mysql';
9
+
10
+ interface BetterAuthDatabaseProviderBuildContext {
11
+ hubDialect: DbDialect;
12
+ usePlural: boolean;
13
+ camelCase: boolean;
14
+ }
15
+ interface BetterAuthDatabaseProviderSetupContext {
16
+ nuxt: Nuxt;
17
+ options: BetterAuthModuleOptions;
18
+ clientOnly: boolean;
19
+ }
20
+ interface BetterAuthDatabaseProviderEnabledContext extends BetterAuthDatabaseProviderSetupContext {
21
+ hasHubDbAvailable: boolean;
22
+ }
23
+ interface BetterAuthDatabaseProviderDefinition {
24
+ buildDatabaseCode: (ctx: BetterAuthDatabaseProviderBuildContext) => string;
25
+ setup?: (ctx: BetterAuthDatabaseProviderSetupContext) => void | Promise<void>;
26
+ isEnabled?: (ctx: BetterAuthDatabaseProviderEnabledContext) => boolean;
27
+ priority?: number;
28
+ }
7
29
  declare module '@nuxt/schema' {
8
30
  interface NuxtHooks {
9
31
  /**
@@ -12,6 +34,11 @@ declare module '@nuxt/schema' {
12
34
  * @param config - Partial config to merge into the auth options
13
35
  */
14
36
  'better-auth:config:extend': (config: Partial<BetterAuthOptions>) => void | Promise<void>;
37
+ /**
38
+ * Register or override Better Auth database providers.
39
+ * Providers are auto-selected via `isEnabled` + `priority`.
40
+ */
41
+ 'better-auth:database:providers': (providers: Record<string, BetterAuthDatabaseProviderDefinition>) => void | Promise<void>;
15
42
  }
16
43
  }
17
44
 
package/dist/module.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@onmax/nuxt-better-auth",
3
+ "version": "0.0.3",
3
4
  "configKey": "auth",
4
5
  "compatibility": {
5
- "nuxt": ">=3.0.0"
6
+ "nuxt": ">=4.0.0"
6
7
  },
7
- "version": "0.0.2-alpha.9",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
- "unbuild": "3.6.1"
10
+ "unbuild": "unknown"
11
11
  }
12
12
  }