@factiii/auth 0.5.5 → 0.5.7
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/{chunk-KUYH4DBN.mjs → chunk-EHI4P63M.mjs} +0 -8
- package/dist/database-CqnmD1HM.d.mts +148 -0
- package/dist/database-CqnmD1HM.d.ts +148 -0
- package/dist/drizzle.d.mts +60 -0
- package/dist/drizzle.d.ts +60 -0
- package/dist/drizzle.js +308 -0
- package/dist/drizzle.mjs +281 -0
- package/dist/index.d.mts +14 -216
- package/dist/index.d.ts +14 -216
- package/dist/index.js +4 -294
- package/dist/index.mjs +5 -295
- package/dist/validators.d.mts +1 -1
- package/dist/validators.d.ts +1 -1
- package/dist/validators.mjs +1 -1
- package/package.json +6 -1
- package/dist/{hooks-yHGJ7C6_.d.mts → hooks-BXNxNK4S.d.mts} +2 -2
- package/dist/{hooks-yHGJ7C6_.d.ts → hooks-BXNxNK4S.d.ts} +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -4,9 +4,10 @@ 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 {
|
|
8
|
-
export {
|
|
9
|
-
import {
|
|
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';
|
|
9
|
+
import { S as SchemaExtensions, A as AuthHooks } from './hooks-BXNxNK4S.mjs';
|
|
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-BXNxNK4S.mjs';
|
|
10
11
|
|
|
11
12
|
//# sourceMappingURL=TRPCError.d.ts.map
|
|
12
13
|
//#endregion
|
|
@@ -148,215 +149,12 @@ declare function createNoopEmailAdapter(): EmailAdapter;
|
|
|
148
149
|
*/
|
|
149
150
|
declare function createConsoleEmailAdapter(): EmailAdapter;
|
|
150
151
|
|
|
151
|
-
/**
|
|
152
|
-
* ORM-agnostic database adapter interface for @factiii/auth.
|
|
153
|
-
* Implement this interface to use any database/ORM with the auth library.
|
|
154
|
-
*/
|
|
155
|
-
interface AuthUser {
|
|
156
|
-
id: number;
|
|
157
|
-
status: string;
|
|
158
|
-
email: string;
|
|
159
|
-
username: string;
|
|
160
|
-
password: string | null;
|
|
161
|
-
twoFaEnabled: boolean;
|
|
162
|
-
oauthProvider: string | null;
|
|
163
|
-
oauthId: string | null;
|
|
164
|
-
tag: string;
|
|
165
|
-
verifiedHumanAt: Date | null;
|
|
166
|
-
emailVerificationStatus: string;
|
|
167
|
-
otpForEmailVerification: string | null;
|
|
168
|
-
isActive: boolean;
|
|
169
|
-
}
|
|
170
|
-
interface AuthSession {
|
|
171
|
-
id: number;
|
|
172
|
-
userId: number;
|
|
173
|
-
socketId: string | null;
|
|
174
|
-
twoFaSecret: string | null;
|
|
175
|
-
browserName: string;
|
|
176
|
-
issuedAt: Date;
|
|
177
|
-
lastUsed: Date;
|
|
178
|
-
revokedAt: Date | null;
|
|
179
|
-
deviceId: number | null;
|
|
180
|
-
}
|
|
181
|
-
interface AuthOTP {
|
|
182
|
-
id: number;
|
|
183
|
-
code: number;
|
|
184
|
-
expiresAt: Date;
|
|
185
|
-
userId: number;
|
|
186
|
-
}
|
|
187
|
-
interface AuthPasswordReset {
|
|
188
|
-
id: string;
|
|
189
|
-
createdAt: Date;
|
|
190
|
-
userId: number;
|
|
191
|
-
}
|
|
192
|
-
interface CreateUserData {
|
|
193
|
-
username: string;
|
|
194
|
-
email: string;
|
|
195
|
-
password: string | null;
|
|
196
|
-
status: string;
|
|
197
|
-
tag: string;
|
|
198
|
-
twoFaEnabled: boolean;
|
|
199
|
-
emailVerificationStatus: string;
|
|
200
|
-
verifiedHumanAt: Date | null;
|
|
201
|
-
oauthProvider?: string;
|
|
202
|
-
oauthId?: string;
|
|
203
|
-
}
|
|
204
|
-
interface CreateSessionData {
|
|
205
|
-
userId: number;
|
|
206
|
-
browserName: string;
|
|
207
|
-
socketId: string | null;
|
|
208
|
-
[key: string]: unknown;
|
|
209
|
-
}
|
|
210
|
-
type SessionWithUser = AuthSession & {
|
|
211
|
-
user: {
|
|
212
|
-
status: string;
|
|
213
|
-
verifiedHumanAt: Date | null;
|
|
214
|
-
};
|
|
215
|
-
};
|
|
216
|
-
type SessionWithDevice = {
|
|
217
|
-
twoFaSecret: string | null;
|
|
218
|
-
deviceId: number | null;
|
|
219
|
-
device: {
|
|
220
|
-
pushToken: string;
|
|
221
|
-
} | null;
|
|
222
|
-
};
|
|
223
|
-
interface DatabaseAdapter {
|
|
224
|
-
user: {
|
|
225
|
-
findByEmailInsensitive(email: string): Promise<AuthUser | null>;
|
|
226
|
-
findByUsernameInsensitive(username: string): Promise<AuthUser | null>;
|
|
227
|
-
findByEmailOrUsernameInsensitive(identifier: string): Promise<AuthUser | null>;
|
|
228
|
-
findByEmailOrOAuthId(email: string, oauthId: string): Promise<AuthUser | null>;
|
|
229
|
-
findById(id: number): Promise<AuthUser | null>;
|
|
230
|
-
findActiveById(id: number): Promise<AuthUser | null>;
|
|
231
|
-
create(data: CreateUserData): Promise<AuthUser>;
|
|
232
|
-
update(id: number, data: Partial<Omit<AuthUser, 'id'>>): Promise<AuthUser>;
|
|
233
|
-
};
|
|
234
|
-
session: {
|
|
235
|
-
/** Find session by ID with user status and verifiedHumanAt joined. */
|
|
236
|
-
findById(id: number): Promise<SessionWithUser | null>;
|
|
237
|
-
create(data: CreateSessionData): Promise<AuthSession>;
|
|
238
|
-
update(id: number, data: Partial<Pick<AuthSession, 'revokedAt' | 'lastUsed' | 'twoFaSecret' | 'deviceId'>>): Promise<AuthSession>;
|
|
239
|
-
/** Update lastUsed and return session with user's verifiedHumanAt. */
|
|
240
|
-
updateLastUsed(id: number): Promise<AuthSession & {
|
|
241
|
-
user: {
|
|
242
|
-
verifiedHumanAt: Date | null;
|
|
243
|
-
};
|
|
244
|
-
}>;
|
|
245
|
-
/** Set revokedAt on a single session. */
|
|
246
|
-
revoke(id: number): Promise<void>;
|
|
247
|
-
/** Find active (non-revoked) sessions for a user, optionally excluding one. */
|
|
248
|
-
findActiveByUserId(userId: number, excludeSessionId?: number): Promise<Pick<AuthSession, 'id' | 'socketId' | 'userId'>[]>;
|
|
249
|
-
/** Revoke all active sessions for a user, optionally excluding one. */
|
|
250
|
-
revokeAllByUserId(userId: number, excludeSessionId?: number): Promise<void>;
|
|
251
|
-
/** Get twoFaSecret from all sessions that have one for a user. */
|
|
252
|
-
findTwoFaSecretsByUserId(userId: number): Promise<{
|
|
253
|
-
twoFaSecret: string | null;
|
|
254
|
-
}[]>;
|
|
255
|
-
/** Clear twoFaSecret on sessions for a user, optionally excluding one. */
|
|
256
|
-
clearTwoFaSecrets(userId: number, excludeSessionId?: number): Promise<void>;
|
|
257
|
-
/** Find session with device relation for TOTP verification. */
|
|
258
|
-
findByIdWithDevice(id: number, userId: number): Promise<SessionWithDevice | null>;
|
|
259
|
-
/** Revoke other sessions that share a device push token. */
|
|
260
|
-
revokeByDevicePushToken(userId: number, pushToken: string, excludeSessionId: number): Promise<void>;
|
|
261
|
-
/** Clear deviceId on all sessions for a user+device pair. */
|
|
262
|
-
clearDeviceId(userId: number, deviceId: number): Promise<void>;
|
|
263
|
-
};
|
|
264
|
-
otp: {
|
|
265
|
-
findValidByUserAndCode(userId: number, code: number): Promise<AuthOTP | null>;
|
|
266
|
-
create(data: {
|
|
267
|
-
userId: number;
|
|
268
|
-
code: number;
|
|
269
|
-
expiresAt: Date;
|
|
270
|
-
}): Promise<AuthOTP>;
|
|
271
|
-
delete(id: number): Promise<void>;
|
|
272
|
-
};
|
|
273
|
-
passwordReset: {
|
|
274
|
-
findById(id: string): Promise<AuthPasswordReset | null>;
|
|
275
|
-
create(userId: number): Promise<AuthPasswordReset>;
|
|
276
|
-
delete(id: string): Promise<void>;
|
|
277
|
-
deleteAllByUserId(userId: number): Promise<void>;
|
|
278
|
-
};
|
|
279
|
-
device: {
|
|
280
|
-
findByTokenSessionAndUser(pushToken: string, sessionId: number, userId: number): Promise<{
|
|
281
|
-
id: number;
|
|
282
|
-
} | null>;
|
|
283
|
-
upsertByPushToken(pushToken: string, sessionId: number, userId: number): Promise<void>;
|
|
284
|
-
findByUserAndToken(userId: number, pushToken: string): Promise<{
|
|
285
|
-
id: number;
|
|
286
|
-
} | null>;
|
|
287
|
-
disconnectUser(deviceId: number, userId: number): Promise<void>;
|
|
288
|
-
hasRemainingUsers(deviceId: number): Promise<boolean>;
|
|
289
|
-
delete(id: number): Promise<void>;
|
|
290
|
-
};
|
|
291
|
-
admin: {
|
|
292
|
-
findByUserId(userId: number): Promise<{
|
|
293
|
-
ip: string;
|
|
294
|
-
} | null>;
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
152
|
/**
|
|
299
153
|
* Creates a DatabaseAdapter backed by Prisma.
|
|
300
154
|
* Pass your generated PrismaClient instance — its full types are preserved at the call site.
|
|
301
155
|
*/
|
|
302
156
|
declare function createPrismaAdapter(prisma: unknown): DatabaseAdapter;
|
|
303
157
|
|
|
304
|
-
/**
|
|
305
|
-
* A Postgres Drizzle table with column properties accessible by name.
|
|
306
|
-
* `AnyPgTable` is Drizzle's base Postgres table type; intersecting with
|
|
307
|
-
* `Record<string, Column>` exposes the column descriptors for index access.
|
|
308
|
-
*/
|
|
309
|
-
type DrizzleTable = AnyPgTable & Record<string, PgColumn>;
|
|
310
|
-
/**
|
|
311
|
-
* Drizzle table references required by the adapter.
|
|
312
|
-
* Consumers pass their Drizzle Postgres table objects so the adapter
|
|
313
|
-
* can build queries without knowing the schema file location.
|
|
314
|
-
*
|
|
315
|
-
* **Note:** This adapter only supports PostgreSQL via `drizzle-orm/pg-core`.
|
|
316
|
-
*/
|
|
317
|
-
interface DrizzleAdapterTables {
|
|
318
|
-
users: DrizzleTable;
|
|
319
|
-
sessions: DrizzleTable;
|
|
320
|
-
otps: DrizzleTable;
|
|
321
|
-
passwordResets: DrizzleTable;
|
|
322
|
-
devices: DrizzleTable;
|
|
323
|
-
admins: DrizzleTable;
|
|
324
|
-
/** Join table for many-to-many device↔user relation (if applicable). */
|
|
325
|
-
devicesToUsers?: DrizzleTable;
|
|
326
|
-
/** Join table for many-to-many device↔session relation (if applicable). */
|
|
327
|
-
devicesToSessions?: DrizzleTable;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Any `PgDatabase` instance, regardless of the underlying driver
|
|
331
|
-
* (node-postgres, postgres.js, Neon, PGLite, etc.).
|
|
332
|
-
*/
|
|
333
|
-
type AnyPgDatabase = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;
|
|
334
|
-
/**
|
|
335
|
-
* Creates a DatabaseAdapter backed by Drizzle ORM.
|
|
336
|
-
*
|
|
337
|
-
* Usage:
|
|
338
|
-
* ```ts
|
|
339
|
-
* import { drizzle } from 'drizzle-orm/node-postgres';
|
|
340
|
-
* import { createDrizzleAdapter } from '@factiii/auth';
|
|
341
|
-
* import * as schema from './schema';
|
|
342
|
-
*
|
|
343
|
-
* const db = drizzle(pool, { schema });
|
|
344
|
-
* const adapter = createDrizzleAdapter(db, {
|
|
345
|
-
* users: schema.users,
|
|
346
|
-
* sessions: schema.sessions,
|
|
347
|
-
* otps: schema.otps,
|
|
348
|
-
* passwordResets: schema.passwordResets,
|
|
349
|
-
* devices: schema.devices,
|
|
350
|
-
* admins: schema.admins,
|
|
351
|
-
* });
|
|
352
|
-
* ```
|
|
353
|
-
*
|
|
354
|
-
* **Important:** This adapter uses Drizzle's relational query API (`db.query.*`)
|
|
355
|
-
* for joins and `db.insert/update/delete` for mutations. Make sure your Drizzle
|
|
356
|
-
* instance is created with `{ schema }` so relational queries work.
|
|
357
|
-
*/
|
|
358
|
-
declare function createDrizzleAdapter(db: AnyPgDatabase, tables: DrizzleAdapterTables): DatabaseAdapter;
|
|
359
|
-
|
|
360
158
|
/**
|
|
361
159
|
* JWT payload structure
|
|
362
160
|
*/
|
|
@@ -513,9 +311,9 @@ declare function createAuthGuard(config: AuthConfig, t: TrpcBuilder): _trpc_serv
|
|
|
513
311
|
userId: number;
|
|
514
312
|
socketId: string | null;
|
|
515
313
|
sessionId: number;
|
|
516
|
-
ip: string | undefined;
|
|
517
314
|
headers: http.IncomingHttpHeaders;
|
|
518
315
|
res: http.ServerResponse<http.IncomingMessage>;
|
|
316
|
+
ip: string | undefined;
|
|
519
317
|
}, unknown>;
|
|
520
318
|
|
|
521
319
|
/**
|
|
@@ -877,12 +675,12 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
877
675
|
email: zod.ZodString;
|
|
878
676
|
password: zod.ZodEffects<zod.ZodString, string, string>;
|
|
879
677
|
}, "strip", zod.ZodTypeAny, {
|
|
880
|
-
username: string;
|
|
881
678
|
email: string;
|
|
679
|
+
username: string;
|
|
882
680
|
password: string;
|
|
883
681
|
}, {
|
|
884
|
-
username: string;
|
|
885
682
|
email: string;
|
|
683
|
+
username: string;
|
|
886
684
|
password: string;
|
|
887
685
|
}>>["in"] extends infer T_7 ? T_7 extends inferParser<[TExtensions["signup"]] extends [zod.AnyZodObject] ? zod.ZodObject<{
|
|
888
686
|
username: zod.ZodString;
|
|
@@ -901,12 +699,12 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
901
699
|
email: zod.ZodString;
|
|
902
700
|
password: zod.ZodEffects<zod.ZodString, string, string>;
|
|
903
701
|
}, "strip", zod.ZodTypeAny, {
|
|
904
|
-
username: string;
|
|
905
702
|
email: string;
|
|
703
|
+
username: string;
|
|
906
704
|
password: string;
|
|
907
705
|
}, {
|
|
908
|
-
username: string;
|
|
909
706
|
email: string;
|
|
707
|
+
username: string;
|
|
910
708
|
password: string;
|
|
911
709
|
}>>["in"] ? T_7 extends _trpc_server.TRPCUnsetMarker ? void : T_7 : never : never;
|
|
912
710
|
output: {
|
|
@@ -1086,20 +884,20 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
1086
884
|
transformer: true;
|
|
1087
885
|
}>;
|
|
1088
886
|
procedure: _trpc_server.TRPCProcedureBuilder<TrpcContext, Meta, {
|
|
1089
|
-
sessionId: number;
|
|
1090
887
|
userId: number;
|
|
1091
888
|
socketId: string | null;
|
|
1092
|
-
|
|
889
|
+
sessionId: number;
|
|
1093
890
|
headers: http.IncomingHttpHeaders;
|
|
1094
891
|
res: http.ServerResponse<http.IncomingMessage>;
|
|
892
|
+
ip: string | undefined;
|
|
1095
893
|
}, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, false>;
|
|
1096
894
|
authProcedure: _trpc_server.TRPCProcedureBuilder<TrpcContext, Meta, {
|
|
1097
|
-
sessionId: number;
|
|
1098
895
|
userId: number;
|
|
1099
896
|
socketId: string | null;
|
|
1100
|
-
|
|
897
|
+
sessionId: number;
|
|
1101
898
|
headers: http.IncomingHttpHeaders;
|
|
1102
899
|
res: http.ServerResponse<http.IncomingMessage>;
|
|
900
|
+
ip: string | undefined;
|
|
1103
901
|
}, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, false>;
|
|
1104
902
|
createContext: ({ req, res }: CreateHTTPContextOptions) => TrpcContext;
|
|
1105
903
|
};
|
|
@@ -1312,4 +1110,4 @@ declare function verifyTotp(code: string, secret: string): Promise<boolean>;
|
|
|
1312
1110
|
*/
|
|
1313
1111
|
declare function generateOtp(min?: number, max?: number): number;
|
|
1314
1112
|
|
|
1315
|
-
export { type AuthConfig, type AuthFeatures, AuthHooks, type
|
|
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,9 +4,10 @@ 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 {
|
|
8
|
-
export {
|
|
9
|
-
import {
|
|
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';
|
|
9
|
+
import { S as SchemaExtensions, A as AuthHooks } from './hooks-BXNxNK4S.js';
|
|
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-BXNxNK4S.js';
|
|
10
11
|
|
|
11
12
|
//# sourceMappingURL=TRPCError.d.ts.map
|
|
12
13
|
//#endregion
|
|
@@ -148,215 +149,12 @@ declare function createNoopEmailAdapter(): EmailAdapter;
|
|
|
148
149
|
*/
|
|
149
150
|
declare function createConsoleEmailAdapter(): EmailAdapter;
|
|
150
151
|
|
|
151
|
-
/**
|
|
152
|
-
* ORM-agnostic database adapter interface for @factiii/auth.
|
|
153
|
-
* Implement this interface to use any database/ORM with the auth library.
|
|
154
|
-
*/
|
|
155
|
-
interface AuthUser {
|
|
156
|
-
id: number;
|
|
157
|
-
status: string;
|
|
158
|
-
email: string;
|
|
159
|
-
username: string;
|
|
160
|
-
password: string | null;
|
|
161
|
-
twoFaEnabled: boolean;
|
|
162
|
-
oauthProvider: string | null;
|
|
163
|
-
oauthId: string | null;
|
|
164
|
-
tag: string;
|
|
165
|
-
verifiedHumanAt: Date | null;
|
|
166
|
-
emailVerificationStatus: string;
|
|
167
|
-
otpForEmailVerification: string | null;
|
|
168
|
-
isActive: boolean;
|
|
169
|
-
}
|
|
170
|
-
interface AuthSession {
|
|
171
|
-
id: number;
|
|
172
|
-
userId: number;
|
|
173
|
-
socketId: string | null;
|
|
174
|
-
twoFaSecret: string | null;
|
|
175
|
-
browserName: string;
|
|
176
|
-
issuedAt: Date;
|
|
177
|
-
lastUsed: Date;
|
|
178
|
-
revokedAt: Date | null;
|
|
179
|
-
deviceId: number | null;
|
|
180
|
-
}
|
|
181
|
-
interface AuthOTP {
|
|
182
|
-
id: number;
|
|
183
|
-
code: number;
|
|
184
|
-
expiresAt: Date;
|
|
185
|
-
userId: number;
|
|
186
|
-
}
|
|
187
|
-
interface AuthPasswordReset {
|
|
188
|
-
id: string;
|
|
189
|
-
createdAt: Date;
|
|
190
|
-
userId: number;
|
|
191
|
-
}
|
|
192
|
-
interface CreateUserData {
|
|
193
|
-
username: string;
|
|
194
|
-
email: string;
|
|
195
|
-
password: string | null;
|
|
196
|
-
status: string;
|
|
197
|
-
tag: string;
|
|
198
|
-
twoFaEnabled: boolean;
|
|
199
|
-
emailVerificationStatus: string;
|
|
200
|
-
verifiedHumanAt: Date | null;
|
|
201
|
-
oauthProvider?: string;
|
|
202
|
-
oauthId?: string;
|
|
203
|
-
}
|
|
204
|
-
interface CreateSessionData {
|
|
205
|
-
userId: number;
|
|
206
|
-
browserName: string;
|
|
207
|
-
socketId: string | null;
|
|
208
|
-
[key: string]: unknown;
|
|
209
|
-
}
|
|
210
|
-
type SessionWithUser = AuthSession & {
|
|
211
|
-
user: {
|
|
212
|
-
status: string;
|
|
213
|
-
verifiedHumanAt: Date | null;
|
|
214
|
-
};
|
|
215
|
-
};
|
|
216
|
-
type SessionWithDevice = {
|
|
217
|
-
twoFaSecret: string | null;
|
|
218
|
-
deviceId: number | null;
|
|
219
|
-
device: {
|
|
220
|
-
pushToken: string;
|
|
221
|
-
} | null;
|
|
222
|
-
};
|
|
223
|
-
interface DatabaseAdapter {
|
|
224
|
-
user: {
|
|
225
|
-
findByEmailInsensitive(email: string): Promise<AuthUser | null>;
|
|
226
|
-
findByUsernameInsensitive(username: string): Promise<AuthUser | null>;
|
|
227
|
-
findByEmailOrUsernameInsensitive(identifier: string): Promise<AuthUser | null>;
|
|
228
|
-
findByEmailOrOAuthId(email: string, oauthId: string): Promise<AuthUser | null>;
|
|
229
|
-
findById(id: number): Promise<AuthUser | null>;
|
|
230
|
-
findActiveById(id: number): Promise<AuthUser | null>;
|
|
231
|
-
create(data: CreateUserData): Promise<AuthUser>;
|
|
232
|
-
update(id: number, data: Partial<Omit<AuthUser, 'id'>>): Promise<AuthUser>;
|
|
233
|
-
};
|
|
234
|
-
session: {
|
|
235
|
-
/** Find session by ID with user status and verifiedHumanAt joined. */
|
|
236
|
-
findById(id: number): Promise<SessionWithUser | null>;
|
|
237
|
-
create(data: CreateSessionData): Promise<AuthSession>;
|
|
238
|
-
update(id: number, data: Partial<Pick<AuthSession, 'revokedAt' | 'lastUsed' | 'twoFaSecret' | 'deviceId'>>): Promise<AuthSession>;
|
|
239
|
-
/** Update lastUsed and return session with user's verifiedHumanAt. */
|
|
240
|
-
updateLastUsed(id: number): Promise<AuthSession & {
|
|
241
|
-
user: {
|
|
242
|
-
verifiedHumanAt: Date | null;
|
|
243
|
-
};
|
|
244
|
-
}>;
|
|
245
|
-
/** Set revokedAt on a single session. */
|
|
246
|
-
revoke(id: number): Promise<void>;
|
|
247
|
-
/** Find active (non-revoked) sessions for a user, optionally excluding one. */
|
|
248
|
-
findActiveByUserId(userId: number, excludeSessionId?: number): Promise<Pick<AuthSession, 'id' | 'socketId' | 'userId'>[]>;
|
|
249
|
-
/** Revoke all active sessions for a user, optionally excluding one. */
|
|
250
|
-
revokeAllByUserId(userId: number, excludeSessionId?: number): Promise<void>;
|
|
251
|
-
/** Get twoFaSecret from all sessions that have one for a user. */
|
|
252
|
-
findTwoFaSecretsByUserId(userId: number): Promise<{
|
|
253
|
-
twoFaSecret: string | null;
|
|
254
|
-
}[]>;
|
|
255
|
-
/** Clear twoFaSecret on sessions for a user, optionally excluding one. */
|
|
256
|
-
clearTwoFaSecrets(userId: number, excludeSessionId?: number): Promise<void>;
|
|
257
|
-
/** Find session with device relation for TOTP verification. */
|
|
258
|
-
findByIdWithDevice(id: number, userId: number): Promise<SessionWithDevice | null>;
|
|
259
|
-
/** Revoke other sessions that share a device push token. */
|
|
260
|
-
revokeByDevicePushToken(userId: number, pushToken: string, excludeSessionId: number): Promise<void>;
|
|
261
|
-
/** Clear deviceId on all sessions for a user+device pair. */
|
|
262
|
-
clearDeviceId(userId: number, deviceId: number): Promise<void>;
|
|
263
|
-
};
|
|
264
|
-
otp: {
|
|
265
|
-
findValidByUserAndCode(userId: number, code: number): Promise<AuthOTP | null>;
|
|
266
|
-
create(data: {
|
|
267
|
-
userId: number;
|
|
268
|
-
code: number;
|
|
269
|
-
expiresAt: Date;
|
|
270
|
-
}): Promise<AuthOTP>;
|
|
271
|
-
delete(id: number): Promise<void>;
|
|
272
|
-
};
|
|
273
|
-
passwordReset: {
|
|
274
|
-
findById(id: string): Promise<AuthPasswordReset | null>;
|
|
275
|
-
create(userId: number): Promise<AuthPasswordReset>;
|
|
276
|
-
delete(id: string): Promise<void>;
|
|
277
|
-
deleteAllByUserId(userId: number): Promise<void>;
|
|
278
|
-
};
|
|
279
|
-
device: {
|
|
280
|
-
findByTokenSessionAndUser(pushToken: string, sessionId: number, userId: number): Promise<{
|
|
281
|
-
id: number;
|
|
282
|
-
} | null>;
|
|
283
|
-
upsertByPushToken(pushToken: string, sessionId: number, userId: number): Promise<void>;
|
|
284
|
-
findByUserAndToken(userId: number, pushToken: string): Promise<{
|
|
285
|
-
id: number;
|
|
286
|
-
} | null>;
|
|
287
|
-
disconnectUser(deviceId: number, userId: number): Promise<void>;
|
|
288
|
-
hasRemainingUsers(deviceId: number): Promise<boolean>;
|
|
289
|
-
delete(id: number): Promise<void>;
|
|
290
|
-
};
|
|
291
|
-
admin: {
|
|
292
|
-
findByUserId(userId: number): Promise<{
|
|
293
|
-
ip: string;
|
|
294
|
-
} | null>;
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
152
|
/**
|
|
299
153
|
* Creates a DatabaseAdapter backed by Prisma.
|
|
300
154
|
* Pass your generated PrismaClient instance — its full types are preserved at the call site.
|
|
301
155
|
*/
|
|
302
156
|
declare function createPrismaAdapter(prisma: unknown): DatabaseAdapter;
|
|
303
157
|
|
|
304
|
-
/**
|
|
305
|
-
* A Postgres Drizzle table with column properties accessible by name.
|
|
306
|
-
* `AnyPgTable` is Drizzle's base Postgres table type; intersecting with
|
|
307
|
-
* `Record<string, Column>` exposes the column descriptors for index access.
|
|
308
|
-
*/
|
|
309
|
-
type DrizzleTable = AnyPgTable & Record<string, PgColumn>;
|
|
310
|
-
/**
|
|
311
|
-
* Drizzle table references required by the adapter.
|
|
312
|
-
* Consumers pass their Drizzle Postgres table objects so the adapter
|
|
313
|
-
* can build queries without knowing the schema file location.
|
|
314
|
-
*
|
|
315
|
-
* **Note:** This adapter only supports PostgreSQL via `drizzle-orm/pg-core`.
|
|
316
|
-
*/
|
|
317
|
-
interface DrizzleAdapterTables {
|
|
318
|
-
users: DrizzleTable;
|
|
319
|
-
sessions: DrizzleTable;
|
|
320
|
-
otps: DrizzleTable;
|
|
321
|
-
passwordResets: DrizzleTable;
|
|
322
|
-
devices: DrizzleTable;
|
|
323
|
-
admins: DrizzleTable;
|
|
324
|
-
/** Join table for many-to-many device↔user relation (if applicable). */
|
|
325
|
-
devicesToUsers?: DrizzleTable;
|
|
326
|
-
/** Join table for many-to-many device↔session relation (if applicable). */
|
|
327
|
-
devicesToSessions?: DrizzleTable;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Any `PgDatabase` instance, regardless of the underlying driver
|
|
331
|
-
* (node-postgres, postgres.js, Neon, PGLite, etc.).
|
|
332
|
-
*/
|
|
333
|
-
type AnyPgDatabase = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;
|
|
334
|
-
/**
|
|
335
|
-
* Creates a DatabaseAdapter backed by Drizzle ORM.
|
|
336
|
-
*
|
|
337
|
-
* Usage:
|
|
338
|
-
* ```ts
|
|
339
|
-
* import { drizzle } from 'drizzle-orm/node-postgres';
|
|
340
|
-
* import { createDrizzleAdapter } from '@factiii/auth';
|
|
341
|
-
* import * as schema from './schema';
|
|
342
|
-
*
|
|
343
|
-
* const db = drizzle(pool, { schema });
|
|
344
|
-
* const adapter = createDrizzleAdapter(db, {
|
|
345
|
-
* users: schema.users,
|
|
346
|
-
* sessions: schema.sessions,
|
|
347
|
-
* otps: schema.otps,
|
|
348
|
-
* passwordResets: schema.passwordResets,
|
|
349
|
-
* devices: schema.devices,
|
|
350
|
-
* admins: schema.admins,
|
|
351
|
-
* });
|
|
352
|
-
* ```
|
|
353
|
-
*
|
|
354
|
-
* **Important:** This adapter uses Drizzle's relational query API (`db.query.*`)
|
|
355
|
-
* for joins and `db.insert/update/delete` for mutations. Make sure your Drizzle
|
|
356
|
-
* instance is created with `{ schema }` so relational queries work.
|
|
357
|
-
*/
|
|
358
|
-
declare function createDrizzleAdapter(db: AnyPgDatabase, tables: DrizzleAdapterTables): DatabaseAdapter;
|
|
359
|
-
|
|
360
158
|
/**
|
|
361
159
|
* JWT payload structure
|
|
362
160
|
*/
|
|
@@ -513,9 +311,9 @@ declare function createAuthGuard(config: AuthConfig, t: TrpcBuilder): _trpc_serv
|
|
|
513
311
|
userId: number;
|
|
514
312
|
socketId: string | null;
|
|
515
313
|
sessionId: number;
|
|
516
|
-
ip: string | undefined;
|
|
517
314
|
headers: http.IncomingHttpHeaders;
|
|
518
315
|
res: http.ServerResponse<http.IncomingMessage>;
|
|
316
|
+
ip: string | undefined;
|
|
519
317
|
}, unknown>;
|
|
520
318
|
|
|
521
319
|
/**
|
|
@@ -877,12 +675,12 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
877
675
|
email: zod.ZodString;
|
|
878
676
|
password: zod.ZodEffects<zod.ZodString, string, string>;
|
|
879
677
|
}, "strip", zod.ZodTypeAny, {
|
|
880
|
-
username: string;
|
|
881
678
|
email: string;
|
|
679
|
+
username: string;
|
|
882
680
|
password: string;
|
|
883
681
|
}, {
|
|
884
|
-
username: string;
|
|
885
682
|
email: string;
|
|
683
|
+
username: string;
|
|
886
684
|
password: string;
|
|
887
685
|
}>>["in"] extends infer T_7 ? T_7 extends inferParser<[TExtensions["signup"]] extends [zod.AnyZodObject] ? zod.ZodObject<{
|
|
888
686
|
username: zod.ZodString;
|
|
@@ -901,12 +699,12 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
901
699
|
email: zod.ZodString;
|
|
902
700
|
password: zod.ZodEffects<zod.ZodString, string, string>;
|
|
903
701
|
}, "strip", zod.ZodTypeAny, {
|
|
904
|
-
username: string;
|
|
905
702
|
email: string;
|
|
703
|
+
username: string;
|
|
906
704
|
password: string;
|
|
907
705
|
}, {
|
|
908
|
-
username: string;
|
|
909
706
|
email: string;
|
|
707
|
+
username: string;
|
|
910
708
|
password: string;
|
|
911
709
|
}>>["in"] ? T_7 extends _trpc_server.TRPCUnsetMarker ? void : T_7 : never : never;
|
|
912
710
|
output: {
|
|
@@ -1086,20 +884,20 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
1086
884
|
transformer: true;
|
|
1087
885
|
}>;
|
|
1088
886
|
procedure: _trpc_server.TRPCProcedureBuilder<TrpcContext, Meta, {
|
|
1089
|
-
sessionId: number;
|
|
1090
887
|
userId: number;
|
|
1091
888
|
socketId: string | null;
|
|
1092
|
-
|
|
889
|
+
sessionId: number;
|
|
1093
890
|
headers: http.IncomingHttpHeaders;
|
|
1094
891
|
res: http.ServerResponse<http.IncomingMessage>;
|
|
892
|
+
ip: string | undefined;
|
|
1095
893
|
}, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, false>;
|
|
1096
894
|
authProcedure: _trpc_server.TRPCProcedureBuilder<TrpcContext, Meta, {
|
|
1097
|
-
sessionId: number;
|
|
1098
895
|
userId: number;
|
|
1099
896
|
socketId: string | null;
|
|
1100
|
-
|
|
897
|
+
sessionId: number;
|
|
1101
898
|
headers: http.IncomingHttpHeaders;
|
|
1102
899
|
res: http.ServerResponse<http.IncomingMessage>;
|
|
900
|
+
ip: string | undefined;
|
|
1103
901
|
}, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, _trpc_server.TRPCUnsetMarker, false>;
|
|
1104
902
|
createContext: ({ req, res }: CreateHTTPContextOptions) => TrpcContext;
|
|
1105
903
|
};
|
|
@@ -1312,4 +1110,4 @@ declare function verifyTotp(code: string, secret: string): Promise<boolean>;
|
|
|
1312
1110
|
*/
|
|
1313
1111
|
declare function generateOtp(min?: number, max?: number): number;
|
|
1314
1112
|
|
|
1315
|
-
export { type AuthConfig, type AuthFeatures, AuthHooks, type
|
|
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 };
|