@invect/user-auth 0.0.1 → 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.
- package/README.md +81 -72
- package/dist/backend/index.cjs +410 -54
- package/dist/backend/index.cjs.map +1 -1
- package/dist/backend/index.d.cts +456 -0
- package/dist/backend/index.d.cts.map +1 -0
- package/dist/backend/index.d.mts +456 -0
- package/dist/backend/index.d.mts.map +1 -0
- package/dist/backend/index.d.ts +28 -18
- package/dist/backend/index.d.ts.map +1 -1
- package/dist/backend/index.mjs +408 -53
- package/dist/backend/index.mjs.map +1 -1
- package/dist/backend/plugin.d.ts +15 -15
- package/dist/backend/plugin.d.ts.map +1 -1
- package/dist/backend/types.d.ts +85 -9
- package/dist/backend/types.d.ts.map +1 -1
- package/dist/frontend/components/ApiKeysDialog.d.ts +17 -0
- package/dist/frontend/components/ApiKeysDialog.d.ts.map +1 -0
- package/dist/frontend/components/AuthenticatedInvect.d.ts +10 -10
- package/dist/frontend/components/SignInForm.d.ts.map +1 -1
- package/dist/frontend/components/SignInPage.d.ts.map +1 -1
- package/dist/frontend/components/UserManagement.d.ts.map +1 -1
- package/dist/frontend/index.cjs +434 -58
- package/dist/frontend/index.cjs.map +1 -1
- package/dist/frontend/index.d.cts +317 -0
- package/dist/frontend/index.d.cts.map +1 -0
- package/dist/frontend/index.d.mts +317 -0
- package/dist/frontend/index.d.mts.map +1 -0
- package/dist/frontend/index.d.ts +3 -1
- package/dist/frontend/index.d.ts.map +1 -1
- package/dist/frontend/index.mjs +418 -43
- package/dist/frontend/index.mjs.map +1 -1
- package/dist/frontend/plugins/authFrontendPlugin.d.ts +2 -2
- package/dist/frontend/plugins/authFrontendPlugin.d.ts.map +1 -1
- package/dist/shared/types.d.cts +49 -0
- package/dist/shared/types.d.cts.map +1 -0
- package/dist/shared/types.d.mts +49 -0
- package/dist/shared/types.d.mts.map +1 -0
- package/package.json +68 -66
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import { InvectIdentity, InvectPlugin, InvectPluginDefinition, InvectPluginSchema, InvectRole } from "@invect/core";
|
|
2
|
+
|
|
3
|
+
//#region src/backend/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Minimal representation of a better-auth User object.
|
|
6
|
+
*/
|
|
7
|
+
interface BetterAuthUser {
|
|
8
|
+
id: string;
|
|
9
|
+
name?: string | null;
|
|
10
|
+
email?: string | null;
|
|
11
|
+
image?: string | null;
|
|
12
|
+
role?: string | null;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Minimal representation of a better-auth Session object.
|
|
17
|
+
*/
|
|
18
|
+
interface BetterAuthSession {
|
|
19
|
+
id: string;
|
|
20
|
+
userId: string;
|
|
21
|
+
token: string;
|
|
22
|
+
expiresAt: Date | string;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The shape returned by `auth.api.getSession()`.
|
|
27
|
+
*/
|
|
28
|
+
interface BetterAuthSessionResult {
|
|
29
|
+
user: BetterAuthUser;
|
|
30
|
+
session: BetterAuthSession;
|
|
31
|
+
}
|
|
32
|
+
interface BetterAuthInternalAdapter {
|
|
33
|
+
findUserByEmail: (email: string) => Promise<BetterAuthUser | {
|
|
34
|
+
user?: BetterAuthUser | null;
|
|
35
|
+
} | null>;
|
|
36
|
+
updateUser: (userId: string, data: Record<string, unknown>) => Promise<BetterAuthUser | null>;
|
|
37
|
+
}
|
|
38
|
+
interface BetterAuthContext {
|
|
39
|
+
internalAdapter?: BetterAuthInternalAdapter;
|
|
40
|
+
}
|
|
41
|
+
interface BetterAuthGlobalAdmin {
|
|
42
|
+
email?: string;
|
|
43
|
+
pw?: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Minimal Auth instance type — what `betterAuth()` returns.
|
|
48
|
+
*
|
|
49
|
+
* We intentionally keep this narrow so we don't couple to better-auth's
|
|
50
|
+
* full internal types. The plugin only needs `handler` and `api.getSession`.
|
|
51
|
+
*/
|
|
52
|
+
interface BetterAuthInstance {
|
|
53
|
+
/** Handles HTTP requests — the core request router. */
|
|
54
|
+
handler: (request: Request) => Promise<Response>;
|
|
55
|
+
/** Server-side API methods. */
|
|
56
|
+
api: {
|
|
57
|
+
getSession: (context: {
|
|
58
|
+
headers: Headers;
|
|
59
|
+
}) => Promise<BetterAuthSessionResult | null>;
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
};
|
|
62
|
+
/** Auth options (used to read basePath). */
|
|
63
|
+
options?: {
|
|
64
|
+
basePath?: string;
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
};
|
|
67
|
+
$context?: Promise<BetterAuthContext>;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Cookie attribute options (subset of Better Auth's CookieOptions).
|
|
72
|
+
*/
|
|
73
|
+
interface CookieAttributeOptions {
|
|
74
|
+
secure?: boolean;
|
|
75
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
76
|
+
path?: string;
|
|
77
|
+
domain?: string;
|
|
78
|
+
maxAge?: number;
|
|
79
|
+
httpOnly?: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A reasonable subset of Better Auth's configuration that can be passed
|
|
83
|
+
* through when the plugin creates an internal Better Auth instance.
|
|
84
|
+
*
|
|
85
|
+
* These are ignored when you provide your own `auth` instance.
|
|
86
|
+
*
|
|
87
|
+
* @see https://www.better-auth.com/docs/reference/auth
|
|
88
|
+
*/
|
|
89
|
+
interface BetterAuthPassthroughOptions {
|
|
90
|
+
/** Email and password authentication settings. */
|
|
91
|
+
emailAndPassword?: {
|
|
92
|
+
enabled?: boolean;
|
|
93
|
+
disableSignUp?: boolean;
|
|
94
|
+
requireEmailVerification?: boolean;
|
|
95
|
+
minPasswordLength?: number;
|
|
96
|
+
maxPasswordLength?: number;
|
|
97
|
+
autoSignIn?: boolean;
|
|
98
|
+
revokeSessionsOnPasswordReset?: boolean;
|
|
99
|
+
};
|
|
100
|
+
/** Session configuration. */
|
|
101
|
+
session?: {
|
|
102
|
+
expiresIn?: number;
|
|
103
|
+
updateAge?: number;
|
|
104
|
+
disableSessionRefresh?: boolean;
|
|
105
|
+
freshAge?: number;
|
|
106
|
+
cookieCache?: {
|
|
107
|
+
enabled?: boolean;
|
|
108
|
+
maxAge?: number;
|
|
109
|
+
strategy?: 'compact' | 'jwt' | 'jwe';
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/** Account linking configuration. */
|
|
113
|
+
account?: {
|
|
114
|
+
updateAccountOnSignIn?: boolean;
|
|
115
|
+
accountLinking?: {
|
|
116
|
+
enabled?: boolean;
|
|
117
|
+
disableImplicitLinking?: boolean;
|
|
118
|
+
allowDifferentEmails?: boolean;
|
|
119
|
+
allowUnlinkingAll?: boolean;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
/** Social / OAuth providers (passed directly to Better Auth). */
|
|
123
|
+
socialProviders?: Record<string, unknown>;
|
|
124
|
+
/** Rate limiting. */
|
|
125
|
+
rateLimit?: {
|
|
126
|
+
enabled?: boolean;
|
|
127
|
+
window?: number;
|
|
128
|
+
max?: number;
|
|
129
|
+
};
|
|
130
|
+
/** Advanced options — use with caution. */
|
|
131
|
+
advanced?: {
|
|
132
|
+
useSecureCookies?: boolean;
|
|
133
|
+
disableCSRFCheck?: boolean;
|
|
134
|
+
cookiePrefix?: string;
|
|
135
|
+
defaultCookieAttributes?: CookieAttributeOptions;
|
|
136
|
+
crossSubDomainCookies?: {
|
|
137
|
+
enabled: boolean;
|
|
138
|
+
additionalCookies?: string[];
|
|
139
|
+
domain?: string;
|
|
140
|
+
};
|
|
141
|
+
ipAddress?: {
|
|
142
|
+
ipAddressHeaders?: string[];
|
|
143
|
+
disableIpTracking?: boolean;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
/** Database hooks (lifecycle callbacks on core tables). */
|
|
147
|
+
databaseHooks?: Record<string, unknown>;
|
|
148
|
+
/** Lifecycle hooks (before/after request processing). */
|
|
149
|
+
hooks?: Record<string, unknown>;
|
|
150
|
+
/** Paths to disable (e.g. sign-up). */
|
|
151
|
+
disabledPaths?: string[];
|
|
152
|
+
/**
|
|
153
|
+
* Secret used for encryption, signing and hashing.
|
|
154
|
+
*
|
|
155
|
+
* Better Auth defaults to `BETTER_AUTH_SECRET` or `AUTH_SECRET` env vars.
|
|
156
|
+
* In production, this **must** be set or Better Auth will throw.
|
|
157
|
+
*
|
|
158
|
+
* Generate one with: `openssl rand -base64 32`
|
|
159
|
+
*/
|
|
160
|
+
secret?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Versioned secrets for non-destructive secret rotation.
|
|
163
|
+
*
|
|
164
|
+
* The first entry is the current key used for new encryption.
|
|
165
|
+
* Remaining entries are decryption-only (previous rotations).
|
|
166
|
+
*
|
|
167
|
+
* Can also be set via `BETTER_AUTH_SECRETS` env var:
|
|
168
|
+
* `BETTER_AUTH_SECRETS=2:base64secret,1:base64secret`
|
|
169
|
+
*/
|
|
170
|
+
secrets?: Array<{
|
|
171
|
+
version: number;
|
|
172
|
+
value: string;
|
|
173
|
+
}>;
|
|
174
|
+
/**
|
|
175
|
+
* Configuration for the Better Auth API Key plugin (`@better-auth/api-key`).
|
|
176
|
+
*
|
|
177
|
+
* Set to `true` to enable with defaults, or pass an object to customise.
|
|
178
|
+
* Disabled by default.
|
|
179
|
+
*
|
|
180
|
+
* When enabled, `@better-auth/api-key` must be installed as a dependency.
|
|
181
|
+
*
|
|
182
|
+
* @see https://better-auth.com/docs/plugins/api-key
|
|
183
|
+
*/
|
|
184
|
+
apiKey?: boolean | ApiKeyPluginOptions;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Options forwarded to the `apiKey()` Better Auth plugin.
|
|
188
|
+
*
|
|
189
|
+
* @see https://better-auth.com/docs/plugins/api-key/reference
|
|
190
|
+
*/
|
|
191
|
+
interface ApiKeyPluginOptions {
|
|
192
|
+
/** Default length of generated API keys (excluding prefix). */
|
|
193
|
+
defaultKeyLength?: number;
|
|
194
|
+
/** Default prefix prepended to every generated key. */
|
|
195
|
+
defaultPrefix?: string;
|
|
196
|
+
/** Require a name when creating an API key. */
|
|
197
|
+
requireName?: boolean;
|
|
198
|
+
/** Enable metadata storage on API keys. */
|
|
199
|
+
enableMetadata?: boolean;
|
|
200
|
+
/** Create mock sessions from API keys so existing session guards work. */
|
|
201
|
+
enableSessionForAPIKeys?: boolean;
|
|
202
|
+
/** Disable hashing of API keys (NOT recommended — insecure). */
|
|
203
|
+
disableKeyHashing?: boolean;
|
|
204
|
+
/** Header(s) to read the API key from. @default 'x-invect-token' */
|
|
205
|
+
apiKeyHeaders?: string | string[];
|
|
206
|
+
/** Key expiration defaults. */
|
|
207
|
+
keyExpiration?: {
|
|
208
|
+
defaultExpiresIn?: number | null;
|
|
209
|
+
disableCustomExpiresTime?: boolean;
|
|
210
|
+
minExpiresIn?: number;
|
|
211
|
+
maxExpiresIn?: number;
|
|
212
|
+
};
|
|
213
|
+
/** Rate limiting for API key usage. */
|
|
214
|
+
rateLimit?: {
|
|
215
|
+
enabled?: boolean;
|
|
216
|
+
timeWindow?: number;
|
|
217
|
+
maxRequests?: number;
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Configuration for the User Auth Invect plugin.
|
|
222
|
+
*
|
|
223
|
+
* A light wrapper around [Better Auth](https://better-auth.com).
|
|
224
|
+
*/
|
|
225
|
+
interface AuthenticationPluginOptions {
|
|
226
|
+
/**
|
|
227
|
+
* A configured Better Auth instance (the return value of `betterAuth()`).
|
|
228
|
+
*
|
|
229
|
+
* When omitted, the plugin creates an internal Better Auth instance
|
|
230
|
+
* automatically using Invect's database configuration. This is the
|
|
231
|
+
* recommended approach for simple setups — no separate `auth.ts` file needed.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* // Simple: let the plugin manage better-auth internally
|
|
236
|
+
* authentication({ globalAdmins: [{ email: 'admin@example.com', pw: 'secret' }] });
|
|
237
|
+
*
|
|
238
|
+
* // Advanced: provide your own instance for full control
|
|
239
|
+
* import { betterAuth } from 'better-auth';
|
|
240
|
+
* const auth = betterAuth({ ... });
|
|
241
|
+
* authentication({ auth });
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
auth?: BetterAuthInstance;
|
|
245
|
+
/**
|
|
246
|
+
* Database for the internal better-auth instance.
|
|
247
|
+
*
|
|
248
|
+
* Accepts anything that `betterAuth({ database })` accepts — e.g. a
|
|
249
|
+
* `better-sqlite3` instance, a `pg` Pool, etc.
|
|
250
|
+
*
|
|
251
|
+
* When omitted, the plugin creates a database client from Invect's
|
|
252
|
+
* `database` (connection string + type).
|
|
253
|
+
*
|
|
254
|
+
* Only used when `auth` is **not** provided.
|
|
255
|
+
*/
|
|
256
|
+
database?: unknown;
|
|
257
|
+
/**
|
|
258
|
+
* Base URL for the auth server (used for cookies, CSRF tokens, etc.).
|
|
259
|
+
*
|
|
260
|
+
* Defaults to `BETTER_AUTH_URL` env var, or `http://localhost:PORT`.
|
|
261
|
+
*
|
|
262
|
+
* Only used when `auth` is **not** provided.
|
|
263
|
+
*/
|
|
264
|
+
baseURL?: string;
|
|
265
|
+
/**
|
|
266
|
+
* Origins trusted for CORS / cookie sharing.
|
|
267
|
+
*
|
|
268
|
+
* Defaults to common local development origins plus the `baseURL`.
|
|
269
|
+
*
|
|
270
|
+
* Only used when `auth` is **not** provided.
|
|
271
|
+
*/
|
|
272
|
+
trustedOrigins?: string[] | ((request: Request) => string[]);
|
|
273
|
+
/**
|
|
274
|
+
* URL path prefix where better-auth routes are mounted within Invect's
|
|
275
|
+
* plugin endpoint space.
|
|
276
|
+
*
|
|
277
|
+
* Plugin endpoints are served at `/plugins/<prefix>/...`.
|
|
278
|
+
* better-auth's own basePath (usually `/api/auth`) is mapped under this.
|
|
279
|
+
*
|
|
280
|
+
* @default 'auth'
|
|
281
|
+
*/
|
|
282
|
+
prefix?: string;
|
|
283
|
+
/**
|
|
284
|
+
* Map a better-auth user + session to an `InvectIdentity`.
|
|
285
|
+
*
|
|
286
|
+
* Override this to customise role mapping, team resolution, or resource
|
|
287
|
+
* access from your better-auth user model.
|
|
288
|
+
*
|
|
289
|
+
* @default — Uses `user.id`, `user.name`, and maps `user.role` to an Invect role.
|
|
290
|
+
*/
|
|
291
|
+
mapUser?: (user: BetterAuthUser, session: BetterAuthSession) => InvectIdentity | Promise<InvectIdentity>;
|
|
292
|
+
/**
|
|
293
|
+
* Map a better-auth user role string to an Invect role.
|
|
294
|
+
* Only used when `mapUser` is not provided.
|
|
295
|
+
*
|
|
296
|
+
* @default — Maps admin/RBAC roles directly, aliases readonly → viewer,
|
|
297
|
+
* and falls back to default for missing or unknown roles.
|
|
298
|
+
*/
|
|
299
|
+
mapRole?: (role: string | null | undefined) => InvectRole;
|
|
300
|
+
/**
|
|
301
|
+
* Paths (relative to the Invect mount point) that should be accessible
|
|
302
|
+
* without a valid session.
|
|
303
|
+
*
|
|
304
|
+
* The better-auth proxy routes (sign-in, sign-up, callback, etc.) are
|
|
305
|
+
* always public regardless of this setting.
|
|
306
|
+
*
|
|
307
|
+
* @default []
|
|
308
|
+
*/
|
|
309
|
+
publicPaths?: string[];
|
|
310
|
+
/**
|
|
311
|
+
* What to do when session resolution fails (network error, malformed token, etc.).
|
|
312
|
+
*
|
|
313
|
+
* - `'throw'` — Return 401 Unauthorized.
|
|
314
|
+
* - `'continue'` — Set identity to null and proceed (useful for mixed auth).
|
|
315
|
+
*
|
|
316
|
+
* @default 'throw'
|
|
317
|
+
*/
|
|
318
|
+
onSessionError?: 'throw' | 'continue';
|
|
319
|
+
/**
|
|
320
|
+
* Explicit list of global admin accounts to seed and/or promote on startup.
|
|
321
|
+
*
|
|
322
|
+
* Each configured admin is ensured to exist with the `admin` role.
|
|
323
|
+
* This is intentionally explicit; the plugin does not implicitly read
|
|
324
|
+
* admin credentials from environment variables.
|
|
325
|
+
*/
|
|
326
|
+
globalAdmins?: BetterAuthGlobalAdmin[];
|
|
327
|
+
/**
|
|
328
|
+
* Better Auth configuration options passed through to the internal instance.
|
|
329
|
+
*
|
|
330
|
+
* Use this to configure session behaviour, email/password settings,
|
|
331
|
+
* social providers, rate limiting, advanced cookie options, etc.
|
|
332
|
+
* without needing to create your own `betterAuth()` instance.
|
|
333
|
+
*
|
|
334
|
+
* Ignored when `auth` is provided (you already have full control).
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```ts
|
|
338
|
+
* authentication({
|
|
339
|
+
* betterAuthOptions: {
|
|
340
|
+
* session: { expiresIn: 60 * 60 * 24 * 30 }, // 30 days
|
|
341
|
+
* advanced: { useSecureCookies: true },
|
|
342
|
+
* },
|
|
343
|
+
* })
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
betterAuthOptions?: BetterAuthPassthroughOptions;
|
|
347
|
+
/**
|
|
348
|
+
* Enable the Better Auth API Key plugin (`@better-auth/api-key`).
|
|
349
|
+
*
|
|
350
|
+
* Set to `true` to enable with defaults, or pass an options object.
|
|
351
|
+
* Disabled by default.
|
|
352
|
+
*
|
|
353
|
+
* When enabled, users can create and verify API keys for programmatic
|
|
354
|
+
* access to your application. The `apikey` database table will be
|
|
355
|
+
* required.
|
|
356
|
+
*
|
|
357
|
+
* This is a convenience shorthand — equivalent to setting
|
|
358
|
+
* `betterAuthOptions.apiKey`.
|
|
359
|
+
*
|
|
360
|
+
* @see https://better-auth.com/docs/plugins/api-key
|
|
361
|
+
*/
|
|
362
|
+
apiKey?: boolean | ApiKeyPluginOptions;
|
|
363
|
+
/**
|
|
364
|
+
* Frontend plugin (sidebar, routes, providers) for the auth UI.
|
|
365
|
+
*
|
|
366
|
+
* Import from `@invect/user-auth/ui` and pass here.
|
|
367
|
+
* Omit for backend-only setups (Express without React).
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```ts
|
|
371
|
+
* import { authFrontend } from '@invect/user-auth/ui';
|
|
372
|
+
* auth({ frontend: authFrontend })
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
frontend?: unknown;
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/backend/plugin.d.ts
|
|
379
|
+
/**
|
|
380
|
+
* Abstract schema for the user-auth plugin's database tables.
|
|
381
|
+
*
|
|
382
|
+
* These definitions allow the Invect CLI (`npx invect-cli generate`) to include
|
|
383
|
+
* the auth tables when generating Drizzle/Prisma schema files.
|
|
384
|
+
*
|
|
385
|
+
* The shapes match Better Auth's default table structure. If your Better Auth
|
|
386
|
+
* config adds extra fields (e.g., via plugins like `twoFactor`, `organization`),
|
|
387
|
+
* you can extend these in your own config.
|
|
388
|
+
*/
|
|
389
|
+
declare const USER_AUTH_SCHEMA: InvectPluginSchema;
|
|
390
|
+
/**
|
|
391
|
+
* Create the Invect user-auth plugin (a light wrapper around Better Auth).
|
|
392
|
+
*
|
|
393
|
+
* This plugin:
|
|
394
|
+
*
|
|
395
|
+
* 1. **Proxies Better Auth routes** — All of Better Auth's HTTP endpoints
|
|
396
|
+
* (sign-in, sign-up, sign-out, OAuth callbacks, session, etc.) are mounted
|
|
397
|
+
* under the plugin endpoint space at `/plugins/auth/api/auth/*` (configurable).
|
|
398
|
+
*
|
|
399
|
+
* 2. **Resolves sessions → identities** — On every Invect API request, the
|
|
400
|
+
* `onRequest` hook reads the session cookie / bearer token via
|
|
401
|
+
* `auth.api.getSession()` and populates `InvectIdentity`.
|
|
402
|
+
*
|
|
403
|
+
* 3. **Handles authorization** — The `onAuthorize` hook lets Better Auth's
|
|
404
|
+
* session decide whether a request is allowed.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```ts
|
|
408
|
+
* // Simple: let the plugin manage Better Auth internally
|
|
409
|
+
* import { authentication } from '@invect/user-auth';
|
|
410
|
+
*
|
|
411
|
+
* app.use('/invect', createInvectRouter({
|
|
412
|
+
* databaseUrl: 'file:./dev.db',
|
|
413
|
+
* plugins: [authentication({
|
|
414
|
+
* globalAdmins: [{ email: 'admin@co.com', pw: 'secret' }],
|
|
415
|
+
* })],
|
|
416
|
+
* }));
|
|
417
|
+
* ```
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```ts
|
|
421
|
+
* // Advanced: provide your own better-auth instance
|
|
422
|
+
* import { betterAuth } from 'better-auth';
|
|
423
|
+
* import { authentication } from '@invect/user-auth';
|
|
424
|
+
*
|
|
425
|
+
* const auth = betterAuth({
|
|
426
|
+
* database: { ... },
|
|
427
|
+
* emailAndPassword: { enabled: true },
|
|
428
|
+
* // ... your better-auth config
|
|
429
|
+
* });
|
|
430
|
+
*
|
|
431
|
+
* app.use('/invect', createInvectRouter({
|
|
432
|
+
* databaseUrl: 'file:./dev.db',
|
|
433
|
+
* plugins: [authentication({ auth })],
|
|
434
|
+
* }));
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
declare function authentication(options: AuthenticationPluginOptions): InvectPlugin;
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/backend/index.d.ts
|
|
440
|
+
/**
|
|
441
|
+
* Create the auth plugin definition for Invect config.
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```ts
|
|
445
|
+
* // Express (backend only):
|
|
446
|
+
* auth({ adminEmail: '...' })
|
|
447
|
+
*
|
|
448
|
+
* // Next.js (with frontend):
|
|
449
|
+
* import { authFrontend } from '@invect/user-auth/ui';
|
|
450
|
+
* auth({ adminEmail: '...', frontend: authFrontend })
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
declare function auth(options: AuthenticationPluginOptions): InvectPluginDefinition;
|
|
454
|
+
//#endregion
|
|
455
|
+
export { type ApiKeyPluginOptions, type AuthenticationPluginOptions, type BetterAuthInstance, type BetterAuthPassthroughOptions, type BetterAuthSession, type BetterAuthSessionResult, type BetterAuthUser, USER_AUTH_SCHEMA, auth, authentication };
|
|
456
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/backend/types.ts","../../src/backend/plugin.ts","../../src/backend/index.ts"],"mappings":";;;;;AAcA;UAAiB,cAAA;EACf,EAAA;EACA,IAAA;EACA,KAAA;EACA,KAAA;EACA,IAAA;EAAA,CACC,GAAA;AAAA;;;;UAMc,iBAAA;EACf,EAAA;EACA,MAAA;EACA,KAAA;EACA,SAAA,EAAW,IAAA;EAAA,CACV,GAAA;AAAA;;;;UAMc,uBAAA;EACf,IAAA,EAAM,cAAA;EACN,OAAA,EAAS,iBAAA;AAAA;AAAA,UAGM,yBAAA;EACf,eAAA,GACE,KAAA,aACG,OAAA,CAAQ,cAAA;IAAmB,IAAA,GAAO,cAAA;EAAA;EACvC,UAAA,GAAa,MAAA,UAAgB,IAAA,EAAM,MAAA,sBAA4B,OAAA,CAAQ,cAAA;AAAA;AAAA,UAGxD,iBAAA;EACf,eAAA,GAAkB,yBAAA;AAAA;AAAA,UAGH,qBAAA;EACf,KAAA;EACA,EAAA;EACA,IAAA;AAAA;;;;;;;UASe,kBAAA;EApBV;EAsBL,OAAA,GAAU,OAAA,EAAS,OAAA,KAAY,OAAA,CAAQ,QAAA;EAtBP;EAyBhC,GAAA;IACE,UAAA,GAAa,OAAA;MAAW,OAAA,EAAS,OAAA;IAAA,MAAc,OAAA,CAAQ,uBAAA;IAAA,CACtD,GAAA;EAAA;EA1BoE;EA8BvE,OAAA;IACE,QAAA;IAAA,CACC,GAAA;EAAA;EAGH,QAAA,GAAW,OAAA,CAAQ,iBAAA;EAAA,CAElB,GAAA;AAAA;AA9BH;;;AAAA,UAwCiB,sBAAA;EACf,MAAA;EACA,QAAA;EACA,IAAA;EACA,MAAA;EACA,MAAA;EACA,QAAA;AAAA;;;;;;;;;UAWe,4BAAA;EA7BG;EA+BlB,gBAAA;IACE,OAAA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