@factiii/auth 0.2.0 → 0.4.0
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 +5 -1
- package/dist/{chunk-PYVDWODF.mjs → chunk-EHI4P63M.mjs} +0 -21
- package/dist/{hooks-B41uikq7.d.mts → hooks-BXNxNK4S.d.mts} +1 -55
- package/dist/{hooks-B41uikq7.d.ts → hooks-BXNxNK4S.d.ts} +1 -55
- package/dist/index.d.mts +30 -51
- package/dist/index.d.ts +30 -51
- package/dist/index.js +115 -191
- package/dist/index.mjs +111 -171
- package/dist/validators.d.mts +1 -1
- package/dist/validators.d.ts +1 -1
- package/dist/validators.js +0 -26
- package/dist/validators.mjs +1 -11
- package/package.json +1 -1
- package/prisma/schema.prisma +17 -19
package/dist/index.d.ts
CHANGED
|
@@ -6,9 +6,8 @@ import { PrismaClient } from '@prisma/client';
|
|
|
6
6
|
import * as _trpc_server from '@trpc/server';
|
|
7
7
|
import * as zod from 'zod';
|
|
8
8
|
import { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';
|
|
9
|
-
import { S as SchemaExtensions, A as AuthHooks } from './hooks-
|
|
10
|
-
export { C as ChangePasswordInput, L as LoginInput,
|
|
11
|
-
import { SignOptions } from 'jsonwebtoken';
|
|
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';
|
|
12
11
|
|
|
13
12
|
//# sourceMappingURL=TRPCError.d.ts.map
|
|
14
13
|
//#endregion
|
|
@@ -160,13 +159,6 @@ interface JwtPayload {
|
|
|
160
159
|
exp?: number;
|
|
161
160
|
iat?: number;
|
|
162
161
|
}
|
|
163
|
-
/**
|
|
164
|
-
* Credentials returned after successful authentication
|
|
165
|
-
*/
|
|
166
|
-
interface AuthCredentials {
|
|
167
|
-
accessToken: string;
|
|
168
|
-
refreshToken: string;
|
|
169
|
-
}
|
|
170
162
|
/**
|
|
171
163
|
* Cookie settings for auth tokens
|
|
172
164
|
*/
|
|
@@ -175,8 +167,7 @@ interface CookieSettings {
|
|
|
175
167
|
sameSite: 'Strict' | 'Lax' | 'None';
|
|
176
168
|
domain?: string;
|
|
177
169
|
httpOnly: boolean;
|
|
178
|
-
|
|
179
|
-
refreshTokenPath: string;
|
|
170
|
+
path: string;
|
|
180
171
|
maxAge: number;
|
|
181
172
|
}
|
|
182
173
|
|
|
@@ -219,8 +210,8 @@ declare function createOAuthVerifier(keys: OAuthKeys): (provider: OAuthProvider,
|
|
|
219
210
|
* Token and OTP expiry settings
|
|
220
211
|
*/
|
|
221
212
|
interface TokenSettings {
|
|
222
|
-
/**
|
|
223
|
-
|
|
213
|
+
/** JWT expiry in seconds (default: 30 days) */
|
|
214
|
+
jwtExpiry: number;
|
|
224
215
|
/** Password reset token expiry in ms (default: 1 hour) */
|
|
225
216
|
passwordResetExpiryMs: number;
|
|
226
217
|
/** OTP validity window in ms (default: 15 minutes) */
|
|
@@ -294,8 +285,7 @@ interface AuthConfig<TExtensions extends SchemaExtensions = {}> {
|
|
|
294
285
|
* Cookie storage keys
|
|
295
286
|
*/
|
|
296
287
|
storageKeys?: {
|
|
297
|
-
|
|
298
|
-
refreshToken: string;
|
|
288
|
+
authToken: string;
|
|
299
289
|
};
|
|
300
290
|
/**
|
|
301
291
|
* Schema extensions for adding custom fields to auth inputs
|
|
@@ -309,7 +299,6 @@ declare function createAuthGuard(config: AuthConfig, t: TrpcBuilder): _trpc_serv
|
|
|
309
299
|
userId: number;
|
|
310
300
|
socketId: string | null;
|
|
311
301
|
sessionId: number;
|
|
312
|
-
refreshToken: string | undefined;
|
|
313
302
|
headers: http.IncomingHttpHeaders;
|
|
314
303
|
res: http.ServerResponse<http.IncomingMessage>;
|
|
315
304
|
ip: string | undefined;
|
|
@@ -327,8 +316,7 @@ declare const defaultCookieSettings: CookieSettings;
|
|
|
327
316
|
* Default storage keys
|
|
328
317
|
*/
|
|
329
318
|
declare const defaultStorageKeys: {
|
|
330
|
-
|
|
331
|
-
refreshToken: string;
|
|
319
|
+
authToken: string;
|
|
332
320
|
};
|
|
333
321
|
/**
|
|
334
322
|
* Create a fully resolved auth config with defaults applied
|
|
@@ -343,8 +331,7 @@ declare const defaultAuthConfig: {
|
|
|
343
331
|
tokenSettings: TokenSettings;
|
|
344
332
|
cookieSettings: CookieSettings;
|
|
345
333
|
storageKeys: {
|
|
346
|
-
|
|
347
|
-
refreshToken: string;
|
|
334
|
+
authToken: string;
|
|
348
335
|
};
|
|
349
336
|
};
|
|
350
337
|
|
|
@@ -392,7 +379,6 @@ type Meta = {
|
|
|
392
379
|
interface TrpcContext {
|
|
393
380
|
userId: number | null;
|
|
394
381
|
sessionId: number | null;
|
|
395
|
-
refreshToken: string | null;
|
|
396
382
|
socketId: string | null;
|
|
397
383
|
headers: CreateHTTPContextOptions['req']['headers'];
|
|
398
384
|
res: CreateHTTPContextOptions['res'];
|
|
@@ -877,7 +863,6 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
877
863
|
procedure: _trpc_server.TRPCProcedureBuilder<TrpcContext, Meta, {
|
|
878
864
|
sessionId: number;
|
|
879
865
|
userId: number;
|
|
880
|
-
refreshToken: string | undefined;
|
|
881
866
|
socketId: string | null;
|
|
882
867
|
headers: http.IncomingHttpHeaders;
|
|
883
868
|
res: http.ServerResponse<http.IncomingMessage>;
|
|
@@ -886,7 +871,6 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
886
871
|
authProcedure: _trpc_server.TRPCProcedureBuilder<TrpcContext, Meta, {
|
|
887
872
|
sessionId: number;
|
|
888
873
|
userId: number;
|
|
889
|
-
refreshToken: string | undefined;
|
|
890
874
|
socketId: string | null;
|
|
891
875
|
headers: http.IncomingHttpHeaders;
|
|
892
876
|
res: http.ServerResponse<http.IncomingMessage>;
|
|
@@ -916,76 +900,71 @@ declare function isMobileDevice(userAgent: string): boolean;
|
|
|
916
900
|
declare function isNativeApp(userAgent: string): boolean;
|
|
917
901
|
|
|
918
902
|
/**
|
|
919
|
-
* Default storage
|
|
903
|
+
* Default storage key for auth cookie
|
|
920
904
|
*/
|
|
921
905
|
declare const DEFAULT_STORAGE_KEYS: {
|
|
922
|
-
|
|
923
|
-
REFRESH_TOKEN: string;
|
|
906
|
+
AUTH_TOKEN: string;
|
|
924
907
|
};
|
|
925
908
|
/**
|
|
926
|
-
* Parse auth
|
|
909
|
+
* Parse auth token from cookie header
|
|
927
910
|
* @param cookieHeader - Raw cookie header string
|
|
928
911
|
* @param storageKeys - Custom storage keys (optional)
|
|
929
|
-
* @returns Parsed
|
|
912
|
+
* @returns Parsed auth token
|
|
930
913
|
*/
|
|
931
|
-
declare function
|
|
932
|
-
|
|
933
|
-
refreshToken: string;
|
|
914
|
+
declare function parseAuthCookie(cookieHeader: string | undefined, storageKeys?: {
|
|
915
|
+
authToken: string;
|
|
934
916
|
}): {
|
|
935
|
-
|
|
936
|
-
refreshToken?: string;
|
|
917
|
+
authToken?: string;
|
|
937
918
|
};
|
|
938
919
|
/**
|
|
939
|
-
* Set auth
|
|
920
|
+
* Set auth cookie on response
|
|
940
921
|
* @param res - HTTP response object
|
|
941
|
-
* @param
|
|
922
|
+
* @param authToken - Auth JWT token
|
|
942
923
|
* @param settings - Cookie settings
|
|
943
924
|
* @param storageKeys - Storage key names
|
|
944
925
|
*/
|
|
945
|
-
declare function
|
|
946
|
-
|
|
947
|
-
refreshToken: string;
|
|
926
|
+
declare function setAuthCookie(res: CreateHTTPContextOptions['res'], authToken: string, settings: Partial<CookieSettings>, storageKeys?: {
|
|
927
|
+
authToken: string;
|
|
948
928
|
}): void;
|
|
949
929
|
/**
|
|
950
|
-
* Clear auth
|
|
930
|
+
* Clear auth cookie (for logout)
|
|
951
931
|
* @param res - HTTP response object
|
|
952
932
|
* @param settings - Cookie settings
|
|
953
933
|
* @param storageKeys - Storage key names
|
|
954
934
|
*/
|
|
955
|
-
declare function
|
|
956
|
-
|
|
957
|
-
refreshToken: string;
|
|
935
|
+
declare function clearAuthCookie(res: CreateHTTPContextOptions['res'], settings: Partial<CookieSettings>, storageKeys?: {
|
|
936
|
+
authToken: string;
|
|
958
937
|
}): void;
|
|
959
938
|
|
|
960
939
|
/**
|
|
961
|
-
* Options for creating
|
|
940
|
+
* Options for creating auth tokens
|
|
962
941
|
*/
|
|
963
942
|
interface CreateTokenOptions {
|
|
964
943
|
secret: string;
|
|
965
|
-
expiresIn:
|
|
944
|
+
expiresIn: number;
|
|
966
945
|
}
|
|
967
946
|
/**
|
|
968
|
-
* Options for verifying
|
|
947
|
+
* Options for verifying auth tokens
|
|
969
948
|
*/
|
|
970
949
|
interface VerifyTokenOptions {
|
|
971
950
|
secret: string;
|
|
972
951
|
ignoreExpiration?: boolean;
|
|
973
952
|
}
|
|
974
953
|
/**
|
|
975
|
-
* Create a JWT
|
|
954
|
+
* Create a JWT auth token
|
|
976
955
|
* @param payload - Token payload containing session and user info
|
|
977
956
|
* @param options - Token creation options
|
|
978
957
|
* @returns Signed JWT token
|
|
979
958
|
*/
|
|
980
|
-
declare function
|
|
959
|
+
declare function createAuthToken(payload: Omit<JwtPayload, 'exp' | 'iat'>, options: CreateTokenOptions): string;
|
|
981
960
|
/**
|
|
982
|
-
* Verify and decode a JWT
|
|
961
|
+
* Verify and decode a JWT auth token
|
|
983
962
|
* @param token - JWT token to verify
|
|
984
963
|
* @param options - Verification options
|
|
985
964
|
* @returns Decoded token payload
|
|
986
965
|
* @throws Error if token is invalid or expired
|
|
987
966
|
*/
|
|
988
|
-
declare function
|
|
967
|
+
declare function verifyAuthToken(token: string, options: VerifyTokenOptions): JwtPayload;
|
|
989
968
|
/**
|
|
990
969
|
* Decode a JWT token without verification
|
|
991
970
|
* @param token - JWT token to decode
|
|
@@ -1060,4 +1039,4 @@ declare function verifyTotp(code: string, secret: string): Promise<boolean>;
|
|
|
1060
1039
|
*/
|
|
1061
1040
|
declare function generateOtp(min?: number, max?: number): number;
|
|
1062
1041
|
|
|
1063
|
-
export { type AuthConfig, type AuthFeatures, AuthHooks, type AuthRouter, DEFAULT_STORAGE_KEYS, type EmailAdapter, type OAuthKeys, type OAuthProvider, type OAuthResult, OAuthVerificationError, SchemaExtensions, type TokenSettings, type TrpcContext, cleanBase32String,
|
|
1042
|
+
export { type AuthConfig, type AuthFeatures, AuthHooks, type AuthRouter, DEFAULT_STORAGE_KEYS, type EmailAdapter, type OAuthKeys, type OAuthProvider, type OAuthResult, OAuthVerificationError, SchemaExtensions, type TokenSettings, type TrpcContext, cleanBase32String, clearAuthCookie, comparePassword, createAuthConfig, createAuthGuard, createAuthRouter, createAuthToken, createConsoleEmailAdapter, createNoopEmailAdapter, createOAuthVerifier, decodeToken, defaultAuthConfig, defaultCookieSettings, defaultStorageKeys, defaultTokenSettings, detectBrowser, generateOtp, generateTotpCode, generateTotpSecret, hashPassword, isMobileDevice, isNativeApp, isTokenExpiredError, isTokenInvalidError, parseAuthCookie, setAuthCookie, validatePasswordStrength, verifyAuthToken, verifyTotp };
|