@neutralauth/internal-auth 0.10.11

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 (147) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +39 -0
  3. package/dist/auth-config.d.ts +43 -0
  4. package/dist/auth-config.d.ts.map +1 -0
  5. package/dist/auth-config.js +43 -0
  6. package/dist/auth-config.js.map +1 -0
  7. package/dist/auth-options.d.ts +3 -0
  8. package/dist/auth-options.d.ts.map +1 -0
  9. package/dist/auth-options.js +40 -0
  10. package/dist/auth-options.js.map +1 -0
  11. package/dist/auth.d.ts +2 -0
  12. package/dist/auth.d.ts.map +1 -0
  13. package/dist/auth.js +4 -0
  14. package/dist/auth.js.map +1 -0
  15. package/dist/client/adapter-utils.d.ts +66 -0
  16. package/dist/client/adapter-utils.d.ts.map +1 -0
  17. package/dist/client/adapter-utils.js +437 -0
  18. package/dist/client/adapter-utils.js.map +1 -0
  19. package/dist/client/adapter.d.ts +14 -0
  20. package/dist/client/adapter.d.ts.map +1 -0
  21. package/dist/client/adapter.js +274 -0
  22. package/dist/client/adapter.js.map +1 -0
  23. package/dist/client/create-api.d.ts +141 -0
  24. package/dist/client/create-api.d.ts.map +1 -0
  25. package/dist/client/create-api.js +205 -0
  26. package/dist/client/create-api.js.map +1 -0
  27. package/dist/client/create-client.d.ts +183 -0
  28. package/dist/client/create-client.d.ts.map +1 -0
  29. package/dist/client/create-client.js +311 -0
  30. package/dist/client/create-client.js.map +1 -0
  31. package/dist/client/create-schema.d.ts +19 -0
  32. package/dist/client/create-schema.d.ts.map +1 -0
  33. package/dist/client/create-schema.js +114 -0
  34. package/dist/client/create-schema.js.map +1 -0
  35. package/dist/client/index.d.ts +7 -0
  36. package/dist/client/index.d.ts.map +1 -0
  37. package/dist/client/index.js +10 -0
  38. package/dist/client/index.js.map +1 -0
  39. package/dist/client/plugins/index.d.ts +3 -0
  40. package/dist/client/plugins/index.d.ts.map +1 -0
  41. package/dist/client/plugins/index.js +3 -0
  42. package/dist/client/plugins/index.js.map +1 -0
  43. package/dist/component/_generated/api.d.ts +36 -0
  44. package/dist/component/_generated/api.d.ts.map +1 -0
  45. package/dist/component/_generated/api.js +31 -0
  46. package/dist/component/_generated/api.js.map +1 -0
  47. package/dist/component/_generated/component.d.ts +787 -0
  48. package/dist/component/_generated/component.d.ts.map +1 -0
  49. package/dist/component/_generated/component.js +11 -0
  50. package/dist/component/_generated/component.js.map +1 -0
  51. package/dist/component/_generated/dataModel.d.ts +46 -0
  52. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  53. package/dist/component/_generated/dataModel.js +11 -0
  54. package/dist/component/_generated/dataModel.js.map +1 -0
  55. package/dist/component/_generated/server.d.ts +121 -0
  56. package/dist/component/_generated/server.d.ts.map +1 -0
  57. package/dist/component/_generated/server.js +78 -0
  58. package/dist/component/_generated/server.js.map +1 -0
  59. package/dist/component/adapter.d.ts +130 -0
  60. package/dist/component/adapter.d.ts.map +1 -0
  61. package/dist/component/adapter.js +5 -0
  62. package/dist/component/adapter.js.map +1 -0
  63. package/dist/component/adapterTest.d.ts +10 -0
  64. package/dist/component/adapterTest.d.ts.map +1 -0
  65. package/dist/component/adapterTest.js +409 -0
  66. package/dist/component/adapterTest.js.map +1 -0
  67. package/dist/component/convex.config.d.ts +3 -0
  68. package/dist/component/convex.config.d.ts.map +1 -0
  69. package/dist/component/convex.config.js +4 -0
  70. package/dist/component/convex.config.js.map +1 -0
  71. package/dist/component/schema.d.ts +474 -0
  72. package/dist/component/schema.d.ts.map +1 -0
  73. package/dist/component/schema.js +139 -0
  74. package/dist/component/schema.js.map +1 -0
  75. package/dist/nextjs/client.d.ts +4 -0
  76. package/dist/nextjs/client.d.ts.map +1 -0
  77. package/dist/nextjs/client.js +37 -0
  78. package/dist/nextjs/client.js.map +1 -0
  79. package/dist/nextjs/index.d.ts +22 -0
  80. package/dist/nextjs/index.d.ts.map +1 -0
  81. package/dist/nextjs/index.js +98 -0
  82. package/dist/nextjs/index.js.map +1 -0
  83. package/dist/plugins/convex/client.d.ts +6 -0
  84. package/dist/plugins/convex/client.d.ts.map +1 -0
  85. package/dist/plugins/convex/client.js +7 -0
  86. package/dist/plugins/convex/client.js.map +1 -0
  87. package/dist/plugins/convex/index.d.ts +322 -0
  88. package/dist/plugins/convex/index.d.ts.map +1 -0
  89. package/dist/plugins/convex/index.js +422 -0
  90. package/dist/plugins/convex/index.js.map +1 -0
  91. package/dist/plugins/cross-domain/client.d.ts +132 -0
  92. package/dist/plugins/cross-domain/client.d.ts.map +1 -0
  93. package/dist/plugins/cross-domain/client.js +192 -0
  94. package/dist/plugins/cross-domain/client.js.map +1 -0
  95. package/dist/plugins/cross-domain/index.d.ts +51 -0
  96. package/dist/plugins/cross-domain/index.d.ts.map +1 -0
  97. package/dist/plugins/cross-domain/index.js +173 -0
  98. package/dist/plugins/cross-domain/index.js.map +1 -0
  99. package/dist/plugins/index.d.ts +3 -0
  100. package/dist/plugins/index.d.ts.map +1 -0
  101. package/dist/plugins/index.js +3 -0
  102. package/dist/plugins/index.js.map +1 -0
  103. package/dist/react/index.d.ts +80 -0
  104. package/dist/react/index.d.ts.map +1 -0
  105. package/dist/react/index.js +190 -0
  106. package/dist/react/index.js.map +1 -0
  107. package/dist/react-start/index.d.ts +13 -0
  108. package/dist/react-start/index.d.ts.map +1 -0
  109. package/dist/react-start/index.js +101 -0
  110. package/dist/react-start/index.js.map +1 -0
  111. package/dist/utils/index.d.ts +33 -0
  112. package/dist/utils/index.d.ts.map +1 -0
  113. package/dist/utils/index.js +91 -0
  114. package/dist/utils/index.js.map +1 -0
  115. package/package.json +208 -0
  116. package/src/auth-config.ts +80 -0
  117. package/src/auth-options.ts +54 -0
  118. package/src/auth.ts +4 -0
  119. package/src/client/adapter-utils.ts +639 -0
  120. package/src/client/adapter.test.ts +83 -0
  121. package/src/client/adapter.ts +363 -0
  122. package/src/client/create-api.ts +339 -0
  123. package/src/client/create-client.ts +452 -0
  124. package/src/client/create-schema.ts +166 -0
  125. package/src/client/index.ts +22 -0
  126. package/src/client/plugins/index.ts +2 -0
  127. package/src/component/_generated/api.ts +52 -0
  128. package/src/component/_generated/component.ts +2008 -0
  129. package/src/component/_generated/dataModel.ts +60 -0
  130. package/src/component/_generated/server.ts +161 -0
  131. package/src/component/adapter.ts +13 -0
  132. package/src/component/adapterTest.ts +505 -0
  133. package/src/component/convex.config.ts +5 -0
  134. package/src/component/schema.ts +142 -0
  135. package/src/nextjs/client.tsx +54 -0
  136. package/src/nextjs/index.ts +152 -0
  137. package/src/plugins/convex/client.ts +9 -0
  138. package/src/plugins/convex/index.ts +596 -0
  139. package/src/plugins/cross-domain/client.test.ts +217 -0
  140. package/src/plugins/cross-domain/client.ts +234 -0
  141. package/src/plugins/cross-domain/index.ts +199 -0
  142. package/src/plugins/index.ts +2 -0
  143. package/src/react/index.tsx +304 -0
  144. package/src/react-start/index.ts +153 -0
  145. package/src/react-start/vite-env.d.ts +2 -0
  146. package/src/test.ts +18 -0
  147. package/src/utils/index.ts +171 -0
@@ -0,0 +1,322 @@
1
+ import type { Session, User } from "better-auth";
2
+ import type { BetterAuthOptions } from "better-auth/minimal";
3
+ import type { AuthConfig } from "convex/server";
4
+ export declare const JWT_COOKIE_NAME = "convex_jwt";
5
+ export declare const convex: (opts: {
6
+ /**
7
+ * @param {AuthConfig} authConfig - Auth config from your Convex project.
8
+ *
9
+ * Typically found in `convex/auth.config.ts`.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // convex/auth.config.ts
14
+ * export default {
15
+ * providers: [getAuthConfigProvider({ jwks: process.env.JWKS })],
16
+ * } satisfies AuthConfig;
17
+ * ```
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // convex/auth.ts
22
+ * import authConfig from './auth.config';
23
+ * export const createAuth = (ctx: GenericCtx<DataModel>) => {
24
+ * return betterAuth({
25
+ * // ...
26
+ * plugins: [convex({ authConfig })],
27
+ * });
28
+ * };
29
+ * ```
30
+ */
31
+ authConfig: AuthConfig;
32
+ /**
33
+ * @param {Object} jwt - JWT options.
34
+ * @param {number} jwt.expirationSeconds - JWT expiration seconds.
35
+ * @param {Function} jwt.definePayload - Function to define the JWT payload. `sessionId` and `iat` are added automatically.
36
+ */
37
+ jwt?: {
38
+ expirationSeconds?: number;
39
+ definePayload?: (session: {
40
+ user: User & Record<string, any>;
41
+ session: Session & Record<string, any>;
42
+ }) => Promise<Record<string, any>> | Record<string, any> | undefined;
43
+ };
44
+ /**
45
+ * @deprecated Use jwt.expirationSeconds instead.
46
+ */
47
+ jwtExpirationSeconds?: number;
48
+ /**
49
+ * @param {string} jwks - Optional static JWKS to avoid fetching from the database.
50
+ *
51
+ * This should be a stringified document from the Better Auth JWKS table. You
52
+ * can create one in the console.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * // convex/auth.ts
57
+ * export const rotateKeys = internalAction({
58
+ * args: {},
59
+ * handler: async (ctx) => {
60
+ * const auth = createAuth(ctx)
61
+ * return await auth.api.rotateKeys()
62
+ * },
63
+ * })
64
+ * ```
65
+ * Run the action and set the JWKS environment variable
66
+ *
67
+ * ```bash
68
+ * npx convex run auth:rotateKeys | npx convex env set JWKS
69
+ * ```
70
+ * Then use it in your auth config and Better Auth options:
71
+ *
72
+ * ```ts
73
+ * // convex/auth.config.ts
74
+ * export default {
75
+ * providers: [getAuthConfigProvider({ jwks: process.env.JWKS })],
76
+ * } satisfies AuthConfig;
77
+ *
78
+ * // convex/auth.ts
79
+ * export const createAuth = (ctx: GenericCtx<DataModel>) => {
80
+ * return betterAuth({
81
+ * // ...
82
+ * plugins: [convex({ authConfig, jwks: process.env.JWKS })],
83
+ * });
84
+ * };
85
+ * ```
86
+ */
87
+ jwks?: string;
88
+ /**
89
+ * @param {boolean} jwksRotateOnTokenGenerationError - Whether to rotate the JWKS on token generation error.
90
+ *
91
+ * Does nothing if a static JWKS is provided.
92
+ *
93
+ * Handles error that occurs when existing JWKS key does not match configured
94
+ * algorithm, which will be common for 0.10 upgrades switching from EdDSA to RS256.
95
+ *
96
+ * @default true
97
+ */
98
+ jwksRotateOnTokenGenerationError?: boolean;
99
+ /**
100
+ * @param {BetterAuthOptions} options - Better Auth options. Not required,
101
+ * currently used to pass the basePath to the oidcProvider plugin.
102
+ */
103
+ options?: BetterAuthOptions;
104
+ }) => {
105
+ id: "convex";
106
+ init: (ctx: import("better-auth").AuthContext<BetterAuthOptions>) => void;
107
+ hooks: {
108
+ before: ({
109
+ matcher(context: import("better-auth").HookEndpointContext): boolean;
110
+ handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
111
+ context: {
112
+ headers: Headers;
113
+ };
114
+ } | undefined>;
115
+ } | {
116
+ matcher: (ctx: import("better-auth").HookEndpointContext) => boolean;
117
+ handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
118
+ context: import("better-call").MiddlewareContext<import("better-call").MiddlewareOptions, import("better-auth").AuthContext<BetterAuthOptions> & {
119
+ returned?: unknown | undefined;
120
+ responseHeaders?: Headers | undefined;
121
+ }>;
122
+ }>;
123
+ })[];
124
+ after: ({
125
+ matcher(): true;
126
+ handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<Response | {
127
+ redirect: boolean;
128
+ url: string;
129
+ } | undefined>;
130
+ } | {
131
+ matcher: (ctx: import("better-auth").HookEndpointContext) => boolean;
132
+ handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
133
+ })[];
134
+ };
135
+ endpoints: {
136
+ getOpenIdConfig: import("better-call").StrictEndpoint<"/convex/.well-known/openid-configuration", {
137
+ method: "GET";
138
+ metadata: {
139
+ isAction: false;
140
+ };
141
+ }, import("better-auth/plugins").OIDCMetadata>;
142
+ getJwks: import("better-call").StrictEndpoint<"/convex/jwks", {
143
+ method: "GET";
144
+ metadata: {
145
+ openapi: {
146
+ description: string;
147
+ responses: {
148
+ "200": {
149
+ description: string;
150
+ content: {
151
+ "application/json": {
152
+ schema: {
153
+ type: "object";
154
+ properties: {
155
+ keys: {
156
+ type: string;
157
+ description: string;
158
+ items: {
159
+ type: string;
160
+ properties: {
161
+ kid: {
162
+ type: string;
163
+ description: string;
164
+ };
165
+ kty: {
166
+ type: string;
167
+ description: string;
168
+ };
169
+ alg: {
170
+ type: string;
171
+ description: string;
172
+ };
173
+ use: {
174
+ type: string;
175
+ description: string;
176
+ enum: string[];
177
+ nullable: boolean;
178
+ };
179
+ n: {
180
+ type: string;
181
+ description: string;
182
+ nullable: boolean;
183
+ };
184
+ e: {
185
+ type: string;
186
+ description: string;
187
+ nullable: boolean;
188
+ };
189
+ crv: {
190
+ type: string;
191
+ description: string;
192
+ nullable: boolean;
193
+ };
194
+ x: {
195
+ type: string;
196
+ description: string;
197
+ nullable: boolean;
198
+ };
199
+ y: {
200
+ type: string;
201
+ description: string;
202
+ nullable: boolean;
203
+ };
204
+ };
205
+ required: string[];
206
+ };
207
+ };
208
+ };
209
+ required: string[];
210
+ };
211
+ };
212
+ };
213
+ };
214
+ };
215
+ };
216
+ };
217
+ }, import("jose").JSONWebKeySet>;
218
+ getLatestJwks: import("better-call").StrictEndpoint<"/convex/latest-jwks", {
219
+ isAction: boolean;
220
+ method: "POST";
221
+ metadata: {
222
+ SERVER_ONLY: true;
223
+ openapi: {
224
+ description: string;
225
+ };
226
+ };
227
+ }, any[]>;
228
+ rotateKeys: import("better-call").StrictEndpoint<"/convex/rotate-keys", {
229
+ isAction: boolean;
230
+ method: "POST";
231
+ metadata: {
232
+ SERVER_ONLY: true;
233
+ openapi: {
234
+ description: string;
235
+ };
236
+ };
237
+ }, any[]>;
238
+ getToken: import("better-call").StrictEndpoint<"/convex/token", {
239
+ method: "GET";
240
+ requireHeaders: true;
241
+ use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
242
+ session: {
243
+ session: Record<string, any> & {
244
+ id: string;
245
+ createdAt: Date;
246
+ updatedAt: Date;
247
+ userId: string;
248
+ expiresAt: Date;
249
+ token: string;
250
+ ipAddress?: string | null | undefined;
251
+ userAgent?: string | null | undefined;
252
+ };
253
+ user: Record<string, any> & {
254
+ id: string;
255
+ createdAt: Date;
256
+ updatedAt: Date;
257
+ email: string;
258
+ emailVerified: boolean;
259
+ name: string;
260
+ image?: string | null | undefined;
261
+ };
262
+ };
263
+ }>)[];
264
+ metadata: {
265
+ openapi: {
266
+ description: string;
267
+ responses: {
268
+ 200: {
269
+ description: string;
270
+ content: {
271
+ "application/json": {
272
+ schema: {
273
+ type: "object";
274
+ properties: {
275
+ token: {
276
+ type: string;
277
+ };
278
+ };
279
+ };
280
+ };
281
+ };
282
+ };
283
+ };
284
+ };
285
+ };
286
+ }, {
287
+ token: string;
288
+ }>;
289
+ };
290
+ schema: {
291
+ jwks: {
292
+ fields: {
293
+ publicKey: {
294
+ type: "string";
295
+ required: true;
296
+ };
297
+ privateKey: {
298
+ type: "string";
299
+ required: true;
300
+ };
301
+ createdAt: {
302
+ type: "date";
303
+ required: true;
304
+ };
305
+ expiresAt: {
306
+ type: "date";
307
+ required: false;
308
+ };
309
+ };
310
+ };
311
+ user: {
312
+ readonly fields: {
313
+ readonly userId: {
314
+ readonly type: "string";
315
+ readonly required: false;
316
+ readonly input: false;
317
+ };
318
+ };
319
+ };
320
+ };
321
+ };
322
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/convex/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,OAAO,EACP,IAAI,EACL,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAU7D,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,eAAe,CAAC;AAE9D,eAAO,MAAM,eAAe,eAAe,CAAC;AA8C5C,eAAO,MAAM,MAAM,GAAI,MAAM;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,UAAU,EAAE,UAAU,CAAC;IACvB;;;;OAIG;IACH,GAAG,CAAC,EAAE;QACJ,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE;YACxB,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YACjC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;SACxC,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;KACtE,CAAC;IACF;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;OASG;IACH,gCAAgC,CAAC,EAAE,OAAO,CAAC;IAC3C;;;OAGG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAjGkE,CAAC;iCAErC,CAAC;;;;;;;;;6BAU7B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsgBH,CAAC"}