@factiii/auth 0.5.4 → 0.5.6

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/dist/index.d.mts CHANGED
@@ -4,6 +4,8 @@ import SuperJSON__default from 'superjson';
4
4
  import * as _trpc_server from '@trpc/server';
5
5
  import * as zod from 'zod';
6
6
  import { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';
7
+ import { D as DatabaseAdapter } from './database-CqnmD1HM.mjs';
8
+ export { A as AuthOTP, a as AuthPasswordReset, b as AuthSession, c as AuthUser, C as CreateSessionData, d as CreateUserData, S as SessionWithDevice, e as SessionWithUser } from './database-CqnmD1HM.mjs';
7
9
  import { S as SchemaExtensions, A as AuthHooks } from './hooks-yHGJ7C6_.mjs';
8
10
  export { C as ChangePasswordInput, L as LoginInput, O as OAuthLoginInput, R as ResetPasswordInput, a as SignupInput, T as TwoFaVerifyInput, V as VerifyEmailInput, b as biometricVerifySchema, c as changePasswordSchema, e as endAllSessionsSchema, l as loginSchema, o as oAuthLoginSchema, r as requestPasswordResetSchema, d as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, f as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-yHGJ7C6_.mjs';
9
11
 
@@ -147,207 +149,11 @@ declare function createNoopEmailAdapter(): EmailAdapter;
147
149
  */
148
150
  declare function createConsoleEmailAdapter(): EmailAdapter;
149
151
 
150
- /**
151
- * ORM-agnostic database adapter interface for @factiii/auth.
152
- * Implement this interface to use any database/ORM with the auth library.
153
- */
154
- interface AuthUser {
155
- id: number;
156
- status: string;
157
- email: string;
158
- username: string;
159
- password: string | null;
160
- twoFaEnabled: boolean;
161
- oauthProvider: string | null;
162
- oauthId: string | null;
163
- tag: string;
164
- verifiedHumanAt: Date | null;
165
- emailVerificationStatus: string;
166
- otpForEmailVerification: string | null;
167
- isActive: boolean;
168
- }
169
- interface AuthSession {
170
- id: number;
171
- userId: number;
172
- socketId: string | null;
173
- twoFaSecret: string | null;
174
- browserName: string;
175
- issuedAt: Date;
176
- lastUsed: Date;
177
- revokedAt: Date | null;
178
- deviceId: number | null;
179
- }
180
- interface AuthOTP {
181
- id: number;
182
- code: number;
183
- expiresAt: Date;
184
- userId: number;
185
- }
186
- interface AuthPasswordReset {
187
- id: string;
188
- createdAt: Date;
189
- userId: number;
190
- }
191
- interface CreateUserData {
192
- username: string;
193
- email: string;
194
- password: string | null;
195
- status: string;
196
- tag: string;
197
- twoFaEnabled: boolean;
198
- emailVerificationStatus: string;
199
- verifiedHumanAt: Date | null;
200
- oauthProvider?: string;
201
- oauthId?: string;
202
- }
203
- interface CreateSessionData {
204
- userId: number;
205
- browserName: string;
206
- socketId: string | null;
207
- [key: string]: unknown;
208
- }
209
- type SessionWithUser = AuthSession & {
210
- user: {
211
- status: string;
212
- verifiedHumanAt: Date | null;
213
- };
214
- };
215
- type SessionWithDevice = {
216
- twoFaSecret: string | null;
217
- deviceId: number | null;
218
- device: {
219
- pushToken: string;
220
- } | null;
221
- };
222
- interface DatabaseAdapter {
223
- user: {
224
- findByEmailInsensitive(email: string): Promise<AuthUser | null>;
225
- findByUsernameInsensitive(username: string): Promise<AuthUser | null>;
226
- findByEmailOrUsernameInsensitive(identifier: string): Promise<AuthUser | null>;
227
- findByEmailOrOAuthId(email: string, oauthId: string): Promise<AuthUser | null>;
228
- findById(id: number): Promise<AuthUser | null>;
229
- findActiveById(id: number): Promise<AuthUser | null>;
230
- create(data: CreateUserData): Promise<AuthUser>;
231
- update(id: number, data: Partial<Omit<AuthUser, 'id'>>): Promise<AuthUser>;
232
- };
233
- session: {
234
- /** Find session by ID with user status and verifiedHumanAt joined. */
235
- findById(id: number): Promise<SessionWithUser | null>;
236
- create(data: CreateSessionData): Promise<AuthSession>;
237
- update(id: number, data: Partial<Pick<AuthSession, 'revokedAt' | 'lastUsed' | 'twoFaSecret' | 'deviceId'>>): Promise<AuthSession>;
238
- /** Update lastUsed and return session with user's verifiedHumanAt. */
239
- updateLastUsed(id: number): Promise<AuthSession & {
240
- user: {
241
- verifiedHumanAt: Date | null;
242
- };
243
- }>;
244
- /** Set revokedAt on a single session. */
245
- revoke(id: number): Promise<void>;
246
- /** Find active (non-revoked) sessions for a user, optionally excluding one. */
247
- findActiveByUserId(userId: number, excludeSessionId?: number): Promise<Pick<AuthSession, 'id' | 'socketId' | 'userId'>[]>;
248
- /** Revoke all active sessions for a user, optionally excluding one. */
249
- revokeAllByUserId(userId: number, excludeSessionId?: number): Promise<void>;
250
- /** Get twoFaSecret from all sessions that have one for a user. */
251
- findTwoFaSecretsByUserId(userId: number): Promise<{
252
- twoFaSecret: string | null;
253
- }[]>;
254
- /** Clear twoFaSecret on sessions for a user, optionally excluding one. */
255
- clearTwoFaSecrets(userId: number, excludeSessionId?: number): Promise<void>;
256
- /** Find session with device relation for TOTP verification. */
257
- findByIdWithDevice(id: number, userId: number): Promise<SessionWithDevice | null>;
258
- /** Revoke other sessions that share a device push token. */
259
- revokeByDevicePushToken(userId: number, pushToken: string, excludeSessionId: number): Promise<void>;
260
- /** Clear deviceId on all sessions for a user+device pair. */
261
- clearDeviceId(userId: number, deviceId: number): Promise<void>;
262
- };
263
- otp: {
264
- findValidByUserAndCode(userId: number, code: number): Promise<AuthOTP | null>;
265
- create(data: {
266
- userId: number;
267
- code: number;
268
- expiresAt: Date;
269
- }): Promise<AuthOTP>;
270
- delete(id: number): Promise<void>;
271
- };
272
- passwordReset: {
273
- findById(id: string): Promise<AuthPasswordReset | null>;
274
- create(userId: number): Promise<AuthPasswordReset>;
275
- delete(id: string): Promise<void>;
276
- deleteAllByUserId(userId: number): Promise<void>;
277
- };
278
- device: {
279
- findByTokenSessionAndUser(pushToken: string, sessionId: number, userId: number): Promise<{
280
- id: number;
281
- } | null>;
282
- upsertByPushToken(pushToken: string, sessionId: number, userId: number): Promise<void>;
283
- findByUserAndToken(userId: number, pushToken: string): Promise<{
284
- id: number;
285
- } | null>;
286
- disconnectUser(deviceId: number, userId: number): Promise<void>;
287
- hasRemainingUsers(deviceId: number): Promise<boolean>;
288
- delete(id: number): Promise<void>;
289
- };
290
- admin: {
291
- findByUserId(userId: number): Promise<{
292
- ip: string;
293
- } | null>;
294
- };
295
- }
296
-
297
- type PrismaClient = any;
298
152
  /**
299
153
  * Creates a DatabaseAdapter backed by Prisma.
300
- * Each method is a direct extraction of existing Prisma calls from the procedures.
301
- */
302
- declare function createPrismaAdapter(prisma: PrismaClient): DatabaseAdapter;
303
-
304
- /**
305
- * Drizzle table references required by the adapter.
306
- * Consumers pass their Drizzle table objects so the adapter
307
- * can build queries without knowing the schema file location.
308
- */
309
- interface DrizzleAdapterTables {
310
- users: any;
311
- sessions: any;
312
- otps: any;
313
- passwordResets: any;
314
- devices: any;
315
- admins: any;
316
- /** Join table for many-to-many device↔user relation (if applicable). */
317
- devicesToUsers?: any;
318
- /** Join table for many-to-many device↔session relation (if applicable). */
319
- devicesToSessions?: any;
320
- }
321
- /**
322
- * Any Drizzle database instance (pg, mysql, better-sqlite3, etc.).
323
- * We keep this generic so consumers aren't locked into a specific driver.
154
+ * Pass your generated PrismaClient instance its full types are preserved at the call site.
324
155
  */
325
- type DrizzleDB = any;
326
- /**
327
- * Creates a DatabaseAdapter backed by Drizzle ORM.
328
- *
329
- * Usage:
330
- * ```ts
331
- * import { drizzle } from 'drizzle-orm/node-postgres';
332
- * import { createDrizzleAdapter } from '@factiii/auth';
333
- * import * as schema from './schema';
334
- *
335
- * const db = drizzle(pool, { schema });
336
- * const adapter = createDrizzleAdapter(db, {
337
- * users: schema.users,
338
- * sessions: schema.sessions,
339
- * otps: schema.otps,
340
- * passwordResets: schema.passwordResets,
341
- * devices: schema.devices,
342
- * admins: schema.admins,
343
- * });
344
- * ```
345
- *
346
- * **Important:** This adapter uses Drizzle's relational query API (`db.query.*`)
347
- * for joins and `db.insert/update/delete` for mutations. Make sure your Drizzle
348
- * instance is created with `{ schema }` so relational queries work.
349
- */
350
- declare function createDrizzleAdapter(db: DrizzleDB, tables: DrizzleAdapterTables): DatabaseAdapter;
156
+ declare function createPrismaAdapter(prisma: unknown): DatabaseAdapter;
351
157
 
352
158
  /**
353
159
  * JWT payload structure
@@ -1222,6 +1028,54 @@ declare function validatePasswordStrength(password: string, minLength?: number):
1222
1028
  error?: string;
1223
1029
  };
1224
1030
 
1031
+ /**
1032
+ * Parameters for creating a session with a signed JWT token.
1033
+ */
1034
+ interface CreateSessionWithTokenParams {
1035
+ /** User ID to create the session for */
1036
+ userId: number;
1037
+ /** Browser name (from user-agent) */
1038
+ browserName: string;
1039
+ /** Socket ID for real-time connections */
1040
+ socketId: string | null;
1041
+ /** Device ID for push notifications */
1042
+ deviceId?: number;
1043
+ /** Extra fields to include in the session record (e.g., instanceId) */
1044
+ extraSessionData?: Record<string, unknown>;
1045
+ }
1046
+ /**
1047
+ * Result of creating a session with a token.
1048
+ */
1049
+ interface SessionWithTokenResult {
1050
+ /** Signed JWT access token */
1051
+ accessToken: string;
1052
+ /** Created session ID */
1053
+ sessionId: number;
1054
+ }
1055
+ /**
1056
+ * Create a session and sign a JWT token.
1057
+ *
1058
+ * Use this for programmatic auth flows (magic links, auto-login, test helpers)
1059
+ * where you need a token without going through the full login procedure.
1060
+ *
1061
+ * @param config - Resolved auth config (from createAuthConfig)
1062
+ * @param params - Session creation parameters
1063
+ * @returns Signed JWT and session ID
1064
+ */
1065
+ declare function createSessionWithToken(config: ResolvedAuthConfig, params: CreateSessionWithTokenParams): Promise<SessionWithTokenResult>;
1066
+ /**
1067
+ * Create a session, sign a JWT token, and set the auth cookie on the response.
1068
+ *
1069
+ * Convenience wrapper around {@link createSessionWithToken} for HTTP handlers
1070
+ * that need to set the cookie immediately.
1071
+ *
1072
+ * @param config - Resolved auth config (from createAuthConfig)
1073
+ * @param params - Session creation parameters
1074
+ * @param res - HTTP response to set the cookie on
1075
+ * @returns Signed JWT and session ID
1076
+ */
1077
+ declare function createSessionWithTokenAndCookie(config: ResolvedAuthConfig, params: CreateSessionWithTokenParams, res: CreateHTTPContextOptions['res']): Promise<SessionWithTokenResult>;
1078
+
1225
1079
  /**
1226
1080
  * Generate a random TOTP secret
1227
1081
  * @param length - Length of the secret (default: 16)
@@ -1256,4 +1110,4 @@ declare function verifyTotp(code: string, secret: string): Promise<boolean>;
1256
1110
  */
1257
1111
  declare function generateOtp(min?: number, max?: number): number;
1258
1112
 
1259
- export { type AuthConfig, type AuthFeatures, AuthHooks, type AuthOTP, type AuthPasswordReset, type AuthRouter, type AuthSession, type AuthUser, type CreateSessionData, type CreateUserData, DEFAULT_STORAGE_KEYS, type DatabaseAdapter, type DrizzleAdapterTables, type EmailAdapter, type OAuthKeys, type OAuthProvider, type OAuthResult, OAuthVerificationError, SchemaExtensions, type SessionWithDevice, type SessionWithUser, type TokenSettings, type TrpcContext, cleanBase32String, clearAuthCookie, comparePassword, createAuthConfig, createAuthGuard, createAuthRouter, createAuthToken, createConsoleEmailAdapter, createDrizzleAdapter, createNoopEmailAdapter, createOAuthVerifier, createPrismaAdapter, decodeToken, defaultAuthConfig, defaultCookieSettings, defaultStorageKeys, defaultTokenSettings, detectBrowser, generateOtp, generateTotpCode, generateTotpSecret, hashPassword, isMobileDevice, isNativeApp, isTokenExpiredError, isTokenInvalidError, parseAuthCookie, setAuthCookie, validatePasswordStrength, verifyAuthToken, verifyTotp };
1113
+ export { type AuthConfig, type AuthFeatures, AuthHooks, type AuthRouter, type CreateSessionWithTokenParams, DEFAULT_STORAGE_KEYS, DatabaseAdapter, type EmailAdapter, type OAuthKeys, type OAuthProvider, type OAuthResult, OAuthVerificationError, type ResolvedAuthConfig, SchemaExtensions, type SessionWithTokenResult, type TokenSettings, type TrpcContext, cleanBase32String, clearAuthCookie, comparePassword, createAuthConfig, createAuthGuard, createAuthRouter, createAuthToken, createConsoleEmailAdapter, createNoopEmailAdapter, createOAuthVerifier, createPrismaAdapter, createSessionWithToken, createSessionWithTokenAndCookie, decodeToken, defaultAuthConfig, defaultCookieSettings, defaultStorageKeys, defaultTokenSettings, detectBrowser, generateOtp, generateTotpCode, generateTotpSecret, hashPassword, isMobileDevice, isNativeApp, isTokenExpiredError, isTokenInvalidError, parseAuthCookie, setAuthCookie, validatePasswordStrength, verifyAuthToken, verifyTotp };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ import SuperJSON__default from 'superjson';
4
4
  import * as _trpc_server from '@trpc/server';
5
5
  import * as zod from 'zod';
6
6
  import { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';
7
+ import { D as DatabaseAdapter } from './database-CqnmD1HM.js';
8
+ export { A as AuthOTP, a as AuthPasswordReset, b as AuthSession, c as AuthUser, C as CreateSessionData, d as CreateUserData, S as SessionWithDevice, e as SessionWithUser } from './database-CqnmD1HM.js';
7
9
  import { S as SchemaExtensions, A as AuthHooks } from './hooks-yHGJ7C6_.js';
8
10
  export { C as ChangePasswordInput, L as LoginInput, O as OAuthLoginInput, R as ResetPasswordInput, a as SignupInput, T as TwoFaVerifyInput, V as VerifyEmailInput, b as biometricVerifySchema, c as changePasswordSchema, e as endAllSessionsSchema, l as loginSchema, o as oAuthLoginSchema, r as requestPasswordResetSchema, d as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, f as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-yHGJ7C6_.js';
9
11
 
@@ -147,207 +149,11 @@ declare function createNoopEmailAdapter(): EmailAdapter;
147
149
  */
148
150
  declare function createConsoleEmailAdapter(): EmailAdapter;
149
151
 
150
- /**
151
- * ORM-agnostic database adapter interface for @factiii/auth.
152
- * Implement this interface to use any database/ORM with the auth library.
153
- */
154
- interface AuthUser {
155
- id: number;
156
- status: string;
157
- email: string;
158
- username: string;
159
- password: string | null;
160
- twoFaEnabled: boolean;
161
- oauthProvider: string | null;
162
- oauthId: string | null;
163
- tag: string;
164
- verifiedHumanAt: Date | null;
165
- emailVerificationStatus: string;
166
- otpForEmailVerification: string | null;
167
- isActive: boolean;
168
- }
169
- interface AuthSession {
170
- id: number;
171
- userId: number;
172
- socketId: string | null;
173
- twoFaSecret: string | null;
174
- browserName: string;
175
- issuedAt: Date;
176
- lastUsed: Date;
177
- revokedAt: Date | null;
178
- deviceId: number | null;
179
- }
180
- interface AuthOTP {
181
- id: number;
182
- code: number;
183
- expiresAt: Date;
184
- userId: number;
185
- }
186
- interface AuthPasswordReset {
187
- id: string;
188
- createdAt: Date;
189
- userId: number;
190
- }
191
- interface CreateUserData {
192
- username: string;
193
- email: string;
194
- password: string | null;
195
- status: string;
196
- tag: string;
197
- twoFaEnabled: boolean;
198
- emailVerificationStatus: string;
199
- verifiedHumanAt: Date | null;
200
- oauthProvider?: string;
201
- oauthId?: string;
202
- }
203
- interface CreateSessionData {
204
- userId: number;
205
- browserName: string;
206
- socketId: string | null;
207
- [key: string]: unknown;
208
- }
209
- type SessionWithUser = AuthSession & {
210
- user: {
211
- status: string;
212
- verifiedHumanAt: Date | null;
213
- };
214
- };
215
- type SessionWithDevice = {
216
- twoFaSecret: string | null;
217
- deviceId: number | null;
218
- device: {
219
- pushToken: string;
220
- } | null;
221
- };
222
- interface DatabaseAdapter {
223
- user: {
224
- findByEmailInsensitive(email: string): Promise<AuthUser | null>;
225
- findByUsernameInsensitive(username: string): Promise<AuthUser | null>;
226
- findByEmailOrUsernameInsensitive(identifier: string): Promise<AuthUser | null>;
227
- findByEmailOrOAuthId(email: string, oauthId: string): Promise<AuthUser | null>;
228
- findById(id: number): Promise<AuthUser | null>;
229
- findActiveById(id: number): Promise<AuthUser | null>;
230
- create(data: CreateUserData): Promise<AuthUser>;
231
- update(id: number, data: Partial<Omit<AuthUser, 'id'>>): Promise<AuthUser>;
232
- };
233
- session: {
234
- /** Find session by ID with user status and verifiedHumanAt joined. */
235
- findById(id: number): Promise<SessionWithUser | null>;
236
- create(data: CreateSessionData): Promise<AuthSession>;
237
- update(id: number, data: Partial<Pick<AuthSession, 'revokedAt' | 'lastUsed' | 'twoFaSecret' | 'deviceId'>>): Promise<AuthSession>;
238
- /** Update lastUsed and return session with user's verifiedHumanAt. */
239
- updateLastUsed(id: number): Promise<AuthSession & {
240
- user: {
241
- verifiedHumanAt: Date | null;
242
- };
243
- }>;
244
- /** Set revokedAt on a single session. */
245
- revoke(id: number): Promise<void>;
246
- /** Find active (non-revoked) sessions for a user, optionally excluding one. */
247
- findActiveByUserId(userId: number, excludeSessionId?: number): Promise<Pick<AuthSession, 'id' | 'socketId' | 'userId'>[]>;
248
- /** Revoke all active sessions for a user, optionally excluding one. */
249
- revokeAllByUserId(userId: number, excludeSessionId?: number): Promise<void>;
250
- /** Get twoFaSecret from all sessions that have one for a user. */
251
- findTwoFaSecretsByUserId(userId: number): Promise<{
252
- twoFaSecret: string | null;
253
- }[]>;
254
- /** Clear twoFaSecret on sessions for a user, optionally excluding one. */
255
- clearTwoFaSecrets(userId: number, excludeSessionId?: number): Promise<void>;
256
- /** Find session with device relation for TOTP verification. */
257
- findByIdWithDevice(id: number, userId: number): Promise<SessionWithDevice | null>;
258
- /** Revoke other sessions that share a device push token. */
259
- revokeByDevicePushToken(userId: number, pushToken: string, excludeSessionId: number): Promise<void>;
260
- /** Clear deviceId on all sessions for a user+device pair. */
261
- clearDeviceId(userId: number, deviceId: number): Promise<void>;
262
- };
263
- otp: {
264
- findValidByUserAndCode(userId: number, code: number): Promise<AuthOTP | null>;
265
- create(data: {
266
- userId: number;
267
- code: number;
268
- expiresAt: Date;
269
- }): Promise<AuthOTP>;
270
- delete(id: number): Promise<void>;
271
- };
272
- passwordReset: {
273
- findById(id: string): Promise<AuthPasswordReset | null>;
274
- create(userId: number): Promise<AuthPasswordReset>;
275
- delete(id: string): Promise<void>;
276
- deleteAllByUserId(userId: number): Promise<void>;
277
- };
278
- device: {
279
- findByTokenSessionAndUser(pushToken: string, sessionId: number, userId: number): Promise<{
280
- id: number;
281
- } | null>;
282
- upsertByPushToken(pushToken: string, sessionId: number, userId: number): Promise<void>;
283
- findByUserAndToken(userId: number, pushToken: string): Promise<{
284
- id: number;
285
- } | null>;
286
- disconnectUser(deviceId: number, userId: number): Promise<void>;
287
- hasRemainingUsers(deviceId: number): Promise<boolean>;
288
- delete(id: number): Promise<void>;
289
- };
290
- admin: {
291
- findByUserId(userId: number): Promise<{
292
- ip: string;
293
- } | null>;
294
- };
295
- }
296
-
297
- type PrismaClient = any;
298
152
  /**
299
153
  * Creates a DatabaseAdapter backed by Prisma.
300
- * Each method is a direct extraction of existing Prisma calls from the procedures.
301
- */
302
- declare function createPrismaAdapter(prisma: PrismaClient): DatabaseAdapter;
303
-
304
- /**
305
- * Drizzle table references required by the adapter.
306
- * Consumers pass their Drizzle table objects so the adapter
307
- * can build queries without knowing the schema file location.
308
- */
309
- interface DrizzleAdapterTables {
310
- users: any;
311
- sessions: any;
312
- otps: any;
313
- passwordResets: any;
314
- devices: any;
315
- admins: any;
316
- /** Join table for many-to-many device↔user relation (if applicable). */
317
- devicesToUsers?: any;
318
- /** Join table for many-to-many device↔session relation (if applicable). */
319
- devicesToSessions?: any;
320
- }
321
- /**
322
- * Any Drizzle database instance (pg, mysql, better-sqlite3, etc.).
323
- * We keep this generic so consumers aren't locked into a specific driver.
154
+ * Pass your generated PrismaClient instance its full types are preserved at the call site.
324
155
  */
325
- type DrizzleDB = any;
326
- /**
327
- * Creates a DatabaseAdapter backed by Drizzle ORM.
328
- *
329
- * Usage:
330
- * ```ts
331
- * import { drizzle } from 'drizzle-orm/node-postgres';
332
- * import { createDrizzleAdapter } from '@factiii/auth';
333
- * import * as schema from './schema';
334
- *
335
- * const db = drizzle(pool, { schema });
336
- * const adapter = createDrizzleAdapter(db, {
337
- * users: schema.users,
338
- * sessions: schema.sessions,
339
- * otps: schema.otps,
340
- * passwordResets: schema.passwordResets,
341
- * devices: schema.devices,
342
- * admins: schema.admins,
343
- * });
344
- * ```
345
- *
346
- * **Important:** This adapter uses Drizzle's relational query API (`db.query.*`)
347
- * for joins and `db.insert/update/delete` for mutations. Make sure your Drizzle
348
- * instance is created with `{ schema }` so relational queries work.
349
- */
350
- declare function createDrizzleAdapter(db: DrizzleDB, tables: DrizzleAdapterTables): DatabaseAdapter;
156
+ declare function createPrismaAdapter(prisma: unknown): DatabaseAdapter;
351
157
 
352
158
  /**
353
159
  * JWT payload structure
@@ -1222,6 +1028,54 @@ declare function validatePasswordStrength(password: string, minLength?: number):
1222
1028
  error?: string;
1223
1029
  };
1224
1030
 
1031
+ /**
1032
+ * Parameters for creating a session with a signed JWT token.
1033
+ */
1034
+ interface CreateSessionWithTokenParams {
1035
+ /** User ID to create the session for */
1036
+ userId: number;
1037
+ /** Browser name (from user-agent) */
1038
+ browserName: string;
1039
+ /** Socket ID for real-time connections */
1040
+ socketId: string | null;
1041
+ /** Device ID for push notifications */
1042
+ deviceId?: number;
1043
+ /** Extra fields to include in the session record (e.g., instanceId) */
1044
+ extraSessionData?: Record<string, unknown>;
1045
+ }
1046
+ /**
1047
+ * Result of creating a session with a token.
1048
+ */
1049
+ interface SessionWithTokenResult {
1050
+ /** Signed JWT access token */
1051
+ accessToken: string;
1052
+ /** Created session ID */
1053
+ sessionId: number;
1054
+ }
1055
+ /**
1056
+ * Create a session and sign a JWT token.
1057
+ *
1058
+ * Use this for programmatic auth flows (magic links, auto-login, test helpers)
1059
+ * where you need a token without going through the full login procedure.
1060
+ *
1061
+ * @param config - Resolved auth config (from createAuthConfig)
1062
+ * @param params - Session creation parameters
1063
+ * @returns Signed JWT and session ID
1064
+ */
1065
+ declare function createSessionWithToken(config: ResolvedAuthConfig, params: CreateSessionWithTokenParams): Promise<SessionWithTokenResult>;
1066
+ /**
1067
+ * Create a session, sign a JWT token, and set the auth cookie on the response.
1068
+ *
1069
+ * Convenience wrapper around {@link createSessionWithToken} for HTTP handlers
1070
+ * that need to set the cookie immediately.
1071
+ *
1072
+ * @param config - Resolved auth config (from createAuthConfig)
1073
+ * @param params - Session creation parameters
1074
+ * @param res - HTTP response to set the cookie on
1075
+ * @returns Signed JWT and session ID
1076
+ */
1077
+ declare function createSessionWithTokenAndCookie(config: ResolvedAuthConfig, params: CreateSessionWithTokenParams, res: CreateHTTPContextOptions['res']): Promise<SessionWithTokenResult>;
1078
+
1225
1079
  /**
1226
1080
  * Generate a random TOTP secret
1227
1081
  * @param length - Length of the secret (default: 16)
@@ -1256,4 +1110,4 @@ declare function verifyTotp(code: string, secret: string): Promise<boolean>;
1256
1110
  */
1257
1111
  declare function generateOtp(min?: number, max?: number): number;
1258
1112
 
1259
- export { type AuthConfig, type AuthFeatures, AuthHooks, type AuthOTP, type AuthPasswordReset, type AuthRouter, type AuthSession, type AuthUser, type CreateSessionData, type CreateUserData, DEFAULT_STORAGE_KEYS, type DatabaseAdapter, type DrizzleAdapterTables, type EmailAdapter, type OAuthKeys, type OAuthProvider, type OAuthResult, OAuthVerificationError, SchemaExtensions, type SessionWithDevice, type SessionWithUser, type TokenSettings, type TrpcContext, cleanBase32String, clearAuthCookie, comparePassword, createAuthConfig, createAuthGuard, createAuthRouter, createAuthToken, createConsoleEmailAdapter, createDrizzleAdapter, createNoopEmailAdapter, createOAuthVerifier, createPrismaAdapter, decodeToken, defaultAuthConfig, defaultCookieSettings, defaultStorageKeys, defaultTokenSettings, detectBrowser, generateOtp, generateTotpCode, generateTotpSecret, hashPassword, isMobileDevice, isNativeApp, isTokenExpiredError, isTokenInvalidError, parseAuthCookie, setAuthCookie, validatePasswordStrength, verifyAuthToken, verifyTotp };
1113
+ export { type AuthConfig, type AuthFeatures, AuthHooks, type AuthRouter, type CreateSessionWithTokenParams, DEFAULT_STORAGE_KEYS, DatabaseAdapter, type EmailAdapter, type OAuthKeys, type OAuthProvider, type OAuthResult, OAuthVerificationError, type ResolvedAuthConfig, SchemaExtensions, type SessionWithTokenResult, type TokenSettings, type TrpcContext, cleanBase32String, clearAuthCookie, comparePassword, createAuthConfig, createAuthGuard, createAuthRouter, createAuthToken, createConsoleEmailAdapter, createNoopEmailAdapter, createOAuthVerifier, createPrismaAdapter, createSessionWithToken, createSessionWithTokenAndCookie, decodeToken, defaultAuthConfig, defaultCookieSettings, defaultStorageKeys, defaultTokenSettings, detectBrowser, generateOtp, generateTotpCode, generateTotpSecret, hashPassword, isMobileDevice, isNativeApp, isTokenExpiredError, isTokenInvalidError, parseAuthCookie, setAuthCookie, validatePasswordStrength, verifyAuthToken, verifyTotp };