@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/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-B41uikq7.js';
10
- export { C as ChangePasswordInput, L as LoginInput, a as LogoutInput, O as OAuthLoginInput, R as ResetPasswordInput, b as SignupInput, T as TwoFaVerifyInput, V as VerifyEmailInput, c as biometricVerifySchema, d as changePasswordSchema, e as endAllSessionsSchema, l as loginSchema, f as logoutSchema, o as oAuthLoginSchema, g as otpLoginRequestSchema, h as otpLoginVerifySchema, r as requestPasswordResetSchema, i as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, j as twoFaSetupSchema, k as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-B41uikq7.js';
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
- accessTokenPath: string;
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
- /** Access token expiry (e.g., '5m', '1h') */
223
- accessTokenExpiry: string;
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
- accessToken: string;
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
- accessToken: string;
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
- accessToken: string;
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 keys for auth cookies
903
+ * Default storage key for auth cookie
920
904
  */
921
905
  declare const DEFAULT_STORAGE_KEYS: {
922
- ACCESS_TOKEN: string;
923
- REFRESH_TOKEN: string;
906
+ AUTH_TOKEN: string;
924
907
  };
925
908
  /**
926
- * Parse auth tokens from cookie header
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 tokens
912
+ * @returns Parsed auth token
930
913
  */
931
- declare function parseAuthCookies(cookieHeader: string | undefined, storageKeys?: {
932
- accessToken: string;
933
- refreshToken: string;
914
+ declare function parseAuthCookie(cookieHeader: string | undefined, storageKeys?: {
915
+ authToken: string;
934
916
  }): {
935
- accessToken?: string;
936
- refreshToken?: string;
917
+ authToken?: string;
937
918
  };
938
919
  /**
939
- * Set auth cookies on response
920
+ * Set auth cookie on response
940
921
  * @param res - HTTP response object
941
- * @param credentials - Access and refresh tokens
922
+ * @param authToken - Auth JWT token
942
923
  * @param settings - Cookie settings
943
924
  * @param storageKeys - Storage key names
944
925
  */
945
- declare function setAuthCookies(res: CreateHTTPContextOptions['res'], credentials: Partial<AuthCredentials>, settings: Partial<CookieSettings>, storageKeys?: {
946
- accessToken: string;
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 cookies (for logout)
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 clearAuthCookies(res: CreateHTTPContextOptions['res'], settings: Partial<CookieSettings>, storageKeys?: {
956
- accessToken: string;
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 access tokens
940
+ * Options for creating auth tokens
962
941
  */
963
942
  interface CreateTokenOptions {
964
943
  secret: string;
965
- expiresIn: SignOptions['expiresIn'];
944
+ expiresIn: number;
966
945
  }
967
946
  /**
968
- * Options for verifying access tokens
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 access token
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 createAccessToken(payload: Omit<JwtPayload, 'exp' | 'iat'>, options: CreateTokenOptions): string;
959
+ declare function createAuthToken(payload: Omit<JwtPayload, 'exp' | 'iat'>, options: CreateTokenOptions): string;
981
960
  /**
982
- * Verify and decode a JWT access token
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 verifyAccessToken(token: string, options: VerifyTokenOptions): JwtPayload;
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, clearAuthCookies, comparePassword, createAccessToken, createAuthConfig, createAuthGuard, createAuthRouter, createConsoleEmailAdapter, createNoopEmailAdapter, createOAuthVerifier, decodeToken, defaultAuthConfig, defaultCookieSettings, defaultStorageKeys, defaultTokenSettings, detectBrowser, generateOtp, generateTotpCode, generateTotpSecret, hashPassword, isMobileDevice, isNativeApp, isTokenExpiredError, isTokenInvalidError, parseAuthCookies, setAuthCookies, validatePasswordStrength, verifyAccessToken, verifyTotp };
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 };