dn-react-router-toolkit 0.2.1 → 0.2.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.
Files changed (43) hide show
  1. package/dist/auth/apple_auth.d.mts +1 -1
  2. package/dist/auth/apple_auth.d.ts +1 -1
  3. package/dist/auth/auth_service.d.mts +3 -3
  4. package/dist/auth/auth_service.d.ts +3 -3
  5. package/dist/auth/client/provider.d.mts +4 -4
  6. package/dist/auth/client/provider.d.ts +4 -4
  7. package/dist/auth/client/provider.js +4 -1
  8. package/dist/auth/client/provider.mjs +4 -1
  9. package/dist/auth/google_auth.d.mts +1 -1
  10. package/dist/auth/google_auth.d.ts +1 -1
  11. package/dist/auth/handlers/find_auth.d.mts +1 -1
  12. package/dist/auth/handlers/find_auth.d.ts +1 -1
  13. package/dist/auth/handlers/login.d.mts +1 -1
  14. package/dist/auth/handlers/login.d.ts +1 -1
  15. package/dist/auth/handlers/login_with_thirdparty.d.mts +1 -1
  16. package/dist/auth/handlers/login_with_thirdparty.d.ts +1 -1
  17. package/dist/auth/handlers/logout.d.mts +1 -1
  18. package/dist/auth/handlers/logout.d.ts +1 -1
  19. package/dist/auth/handlers/refresh.d.mts +1 -1
  20. package/dist/auth/handlers/refresh.d.ts +1 -1
  21. package/dist/auth/handlers/signup.d.mts +1 -1
  22. package/dist/auth/handlers/signup.d.ts +1 -1
  23. package/dist/auth/handlers/signup_with_thirdparty.d.mts +1 -1
  24. package/dist/auth/handlers/signup_with_thirdparty.d.ts +1 -1
  25. package/dist/auth/handlers/thirdparty_auth_callback.d.mts +1 -1
  26. package/dist/auth/handlers/thirdparty_auth_callback.d.ts +1 -1
  27. package/dist/auth/jwt_manager.d.mts +15 -5
  28. package/dist/auth/jwt_manager.d.ts +15 -5
  29. package/dist/auth/jwt_manager.js +3 -3
  30. package/dist/auth/jwt_manager.mjs +3 -3
  31. package/dist/auth/kakao_auth.d.mts +1 -1
  32. package/dist/auth/kakao_auth.d.ts +1 -1
  33. package/dist/auth/thirdparty_auth.d.mts +1 -1
  34. package/dist/auth/thirdparty_auth.d.ts +1 -1
  35. package/dist/auth/with_auth.d.mts +4 -4
  36. package/dist/auth/with_auth.d.ts +4 -4
  37. package/dist/auth/with_auth.js +28 -8
  38. package/dist/auth/with_auth.mjs +28 -8
  39. package/dist/file/handlers/delete_file.d.mts +1 -1
  40. package/dist/file/handlers/delete_file.d.ts +1 -1
  41. package/dist/file/handlers/upload_file.d.mts +1 -1
  42. package/dist/file/handlers/upload_file.d.ts +1 -1
  43. package/package.json +76 -76
@@ -1,8 +1,8 @@
1
1
  import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.mjs';
2
2
  import './auth_service.mjs';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import './jwt_manager.mjs';
5
+ import 'react-router';
6
6
  import '../file/object_storage.mjs';
7
7
  import '@aws-sdk/client-s3';
8
8
  import './auth_repository.mjs';
@@ -1,8 +1,8 @@
1
1
  import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.js';
2
2
  import './auth_service.js';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import './jwt_manager.js';
5
+ import 'react-router';
6
6
  import '../file/object_storage.js';
7
7
  import '@aws-sdk/client-s3';
8
8
  import './auth_repository.js';
@@ -1,6 +1,6 @@
1
1
  import * as jose from 'jose';
2
+ import { JWTManager, AccessTokenPayload } from './jwt_manager.mjs';
2
3
  import * as react_router from 'react-router';
3
- import { JWTManager } from './jwt_manager.mjs';
4
4
  import { ObjectStorage } from '../file/object_storage.mjs';
5
5
  import { AuthRepository } from './auth_repository.mjs';
6
6
  import '@aws-sdk/client-s3';
@@ -18,8 +18,8 @@ declare class AuthService<TFile = unknown> {
18
18
  jwtManager: JWTManager;
19
19
  objectStorage: ObjectStorage;
20
20
  });
21
- verify(request: Request): Promise<jose.JWTPayload | undefined>;
22
- verifyOrRefresh(request: Request): Promise<jose.JWTPayload | undefined>;
21
+ verify(request: Request): Promise<AccessTokenPayload | undefined>;
22
+ verifyOrRefresh(request: Request): Promise<jose.JWTPayload | AccessTokenPayload | undefined>;
23
23
  getAccessTokenFromRequest(request: Request): Promise<any>;
24
24
  getAccessTokenFromCookies(request: Request): Promise<any>;
25
25
  getRefreshTokenFromCookies(request: Request): Promise<any>;
@@ -1,6 +1,6 @@
1
1
  import * as jose from 'jose';
2
+ import { JWTManager, AccessTokenPayload } from './jwt_manager.js';
2
3
  import * as react_router from 'react-router';
3
- import { JWTManager } from './jwt_manager.js';
4
4
  import { ObjectStorage } from '../file/object_storage.js';
5
5
  import { AuthRepository } from './auth_repository.js';
6
6
  import '@aws-sdk/client-s3';
@@ -18,8 +18,8 @@ declare class AuthService<TFile = unknown> {
18
18
  jwtManager: JWTManager;
19
19
  objectStorage: ObjectStorage;
20
20
  });
21
- verify(request: Request): Promise<jose.JWTPayload | undefined>;
22
- verifyOrRefresh(request: Request): Promise<jose.JWTPayload | undefined>;
21
+ verify(request: Request): Promise<AccessTokenPayload | undefined>;
22
+ verifyOrRefresh(request: Request): Promise<jose.JWTPayload | AccessTokenPayload | undefined>;
23
23
  getAccessTokenFromRequest(request: Request): Promise<any>;
24
24
  getAccessTokenFromCookies(request: Request): Promise<any>;
25
25
  getRefreshTokenFromCookies(request: Request): Promise<any>;
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
+ import { AccessTokenPayload } from '../jwt_manager.mjs';
3
+ import 'jose';
2
4
 
3
5
  type AuthContextValue = {
4
- auth?: {
5
- userId: string;
6
- };
6
+ auth: AccessTokenPayload | undefined;
7
7
  login: (id: string, password: string) => Promise<void>;
8
8
  loginWithGoogle: (redirectUrl?: string) => Promise<void>;
9
9
  logout: () => Promise<void>;
@@ -15,7 +15,7 @@ type AuthContextValue = {
15
15
  };
16
16
  declare const AuthContext: React.Context<AuthContextValue>;
17
17
  declare const useAuth: () => AuthContextValue;
18
- declare function AuthProvider({ children, googleAuth }: {
18
+ declare function AuthProvider({ children, googleAuth, }: {
19
19
  children: React.ReactNode;
20
20
  googleAuth?: {
21
21
  googleClientId: string;
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
+ import { AccessTokenPayload } from '../jwt_manager.js';
3
+ import 'jose';
2
4
 
3
5
  type AuthContextValue = {
4
- auth?: {
5
- userId: string;
6
- };
6
+ auth: AccessTokenPayload | undefined;
7
7
  login: (id: string, password: string) => Promise<void>;
8
8
  loginWithGoogle: (redirectUrl?: string) => Promise<void>;
9
9
  logout: () => Promise<void>;
@@ -15,7 +15,7 @@ type AuthContextValue = {
15
15
  };
16
16
  declare const AuthContext: React.Context<AuthContextValue>;
17
17
  declare const useAuth: () => AuthContextValue;
18
- declare function AuthProvider({ children, googleAuth }: {
18
+ declare function AuthProvider({ children, googleAuth, }: {
19
19
  children: React.ReactNode;
20
20
  googleAuth?: {
21
21
  googleClientId: string;
@@ -42,7 +42,10 @@ var AuthContext = (0, import_react2.createContext)({});
42
42
  var useAuth = () => {
43
43
  return (0, import_react2.useContext)(AuthContext);
44
44
  };
45
- function AuthProvider({ children, googleAuth }) {
45
+ function AuthProvider({
46
+ children,
47
+ googleAuth
48
+ }) {
46
49
  const data = (0, import_react_router.useRouteLoaderData)("root");
47
50
  const auth = data?.AUTH;
48
51
  const navigate = (0, import_react_router.useNavigate)();
@@ -6,7 +6,10 @@ var AuthContext = createContext({});
6
6
  var useAuth = () => {
7
7
  return useContext(AuthContext);
8
8
  };
9
- function AuthProvider({ children, googleAuth }) {
9
+ function AuthProvider({
10
+ children,
11
+ googleAuth
12
+ }) {
10
13
  const data = useRouteLoaderData("root");
11
14
  const auth = data?.AUTH;
12
15
  const navigate = useNavigate();
@@ -1,8 +1,8 @@
1
1
  import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.mjs';
2
2
  import './auth_service.mjs';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import './jwt_manager.mjs';
5
+ import 'react-router';
6
6
  import '../file/object_storage.mjs';
7
7
  import '@aws-sdk/client-s3';
8
8
  import './auth_repository.mjs';
@@ -1,8 +1,8 @@
1
1
  import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.js';
2
2
  import './auth_service.js';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import './jwt_manager.js';
5
+ import 'react-router';
6
6
  import '../file/object_storage.js';
7
7
  import '@aws-sdk/client-s3';
8
8
  import './auth_repository.js';
@@ -1,7 +1,7 @@
1
1
  import { AuthService } from '../auth_service.mjs';
2
2
  import 'jose';
3
- import 'react-router';
4
3
  import '../jwt_manager.mjs';
4
+ import 'react-router';
5
5
  import '../../file/object_storage.mjs';
6
6
  import '@aws-sdk/client-s3';
7
7
  import '../auth_repository.mjs';
@@ -1,7 +1,7 @@
1
1
  import { AuthService } from '../auth_service.js';
2
2
  import 'jose';
3
- import 'react-router';
4
3
  import '../jwt_manager.js';
4
+ import 'react-router';
5
5
  import '../../file/object_storage.js';
6
6
  import '@aws-sdk/client-s3';
7
7
  import '../auth_repository.js';
@@ -1,7 +1,7 @@
1
1
  import { AuthService } from '../auth_service.mjs';
2
2
  import 'jose';
3
- import 'react-router';
4
3
  import '../jwt_manager.mjs';
4
+ import 'react-router';
5
5
  import '../../file/object_storage.mjs';
6
6
  import '@aws-sdk/client-s3';
7
7
  import '../auth_repository.mjs';
@@ -1,7 +1,7 @@
1
1
  import { AuthService } from '../auth_service.js';
2
2
  import 'jose';
3
- import 'react-router';
4
3
  import '../jwt_manager.js';
4
+ import 'react-router';
5
5
  import '../../file/object_storage.js';
6
6
  import '@aws-sdk/client-s3';
7
7
  import '../auth_repository.js';
@@ -1,8 +1,8 @@
1
1
  import { ThirdpartyAuth } from '../thirdparty_auth.mjs';
2
2
  import '../auth_service.mjs';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../jwt_manager.mjs';
5
+ import 'react-router';
6
6
  import '../../file/object_storage.mjs';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../auth_repository.mjs';
@@ -1,8 +1,8 @@
1
1
  import { ThirdpartyAuth } from '../thirdparty_auth.js';
2
2
  import '../auth_service.js';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../jwt_manager.js';
5
+ import 'react-router';
6
6
  import '../../file/object_storage.js';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../auth_repository.js';
@@ -1,7 +1,7 @@
1
1
  import { AuthService } from '../auth_service.mjs';
2
2
  import 'jose';
3
- import 'react-router';
4
3
  import '../jwt_manager.mjs';
4
+ import 'react-router';
5
5
  import '../../file/object_storage.mjs';
6
6
  import '@aws-sdk/client-s3';
7
7
  import '../auth_repository.mjs';
@@ -1,7 +1,7 @@
1
1
  import { AuthService } from '../auth_service.js';
2
2
  import 'jose';
3
- import 'react-router';
4
3
  import '../jwt_manager.js';
4
+ import 'react-router';
5
5
  import '../../file/object_storage.js';
6
6
  import '@aws-sdk/client-s3';
7
7
  import '../auth_repository.js';
@@ -1,7 +1,7 @@
1
1
  import { AuthService } from '../auth_service.mjs';
2
2
  import 'jose';
3
- import 'react-router';
4
3
  import '../jwt_manager.mjs';
4
+ import 'react-router';
5
5
  import '../../file/object_storage.mjs';
6
6
  import '@aws-sdk/client-s3';
7
7
  import '../auth_repository.mjs';
@@ -1,7 +1,7 @@
1
1
  import { AuthService } from '../auth_service.js';
2
2
  import 'jose';
3
- import 'react-router';
4
3
  import '../jwt_manager.js';
4
+ import 'react-router';
5
5
  import '../../file/object_storage.js';
6
6
  import '@aws-sdk/client-s3';
7
7
  import '../auth_repository.js';
@@ -1,8 +1,8 @@
1
1
  import { AuthService } from '../auth_service.mjs';
2
2
  import { FileRepository } from '../../file/file_repository.mjs';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../jwt_manager.mjs';
5
+ import 'react-router';
6
6
  import '../../file/object_storage.mjs';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../auth_repository.mjs';
@@ -1,8 +1,8 @@
1
1
  import { AuthService } from '../auth_service.js';
2
2
  import { FileRepository } from '../../file/file_repository.js';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../jwt_manager.js';
5
+ import 'react-router';
6
6
  import '../../file/object_storage.js';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../auth_repository.js';
@@ -1,8 +1,8 @@
1
1
  import { AuthService } from '../auth_service.mjs';
2
2
  import { FileService } from '../../file/file_service.mjs';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../jwt_manager.mjs';
5
+ import 'react-router';
6
6
  import '../../file/object_storage.mjs';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../auth_repository.mjs';
@@ -1,8 +1,8 @@
1
1
  import { AuthService } from '../auth_service.js';
2
2
  import { FileService } from '../../file/file_service.js';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../jwt_manager.js';
5
+ import 'react-router';
6
6
  import '../../file/object_storage.js';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../auth_repository.js';
@@ -1,8 +1,8 @@
1
1
  import { AuthService } from '../auth_service.mjs';
2
2
  import { ThirdpartyAuth } from '../thirdparty_auth.mjs';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../jwt_manager.mjs';
5
+ import 'react-router';
6
6
  import '../../file/object_storage.mjs';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../auth_repository.mjs';
@@ -1,8 +1,8 @@
1
1
  import { AuthService } from '../auth_service.js';
2
2
  import { ThirdpartyAuth } from '../thirdparty_auth.js';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../jwt_manager.js';
5
+ import 'react-router';
6
6
  import '../../file/object_storage.js';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../auth_repository.js';
@@ -1,5 +1,15 @@
1
1
  import { JWTPayload } from 'jose';
2
2
 
3
+ type AccessTokenPayload = {
4
+ userId: string;
5
+ role: string;
6
+ name: string;
7
+ };
8
+ type RefreshTokenPayload = {
9
+ userId: string;
10
+ role: string;
11
+ name: string;
12
+ };
3
13
  declare class JWTManager {
4
14
  siteOrigin?: string;
5
15
  accessTokenSecret: string;
@@ -14,15 +24,15 @@ declare class JWTManager {
14
24
  refreshTokenExpiresIn?: string;
15
25
  });
16
26
  verify(token: string, secret: string): Promise<JWTPayload | undefined>;
17
- verifyAccessToken(token: string): Promise<JWTPayload | undefined>;
18
- verifyRefreshToken(token: string): Promise<JWTPayload | undefined>;
27
+ verifyAccessToken(token: string): Promise<AccessTokenPayload | undefined>;
28
+ verifyRefreshToken(token: string): Promise<RefreshTokenPayload | undefined>;
19
29
  sign(payload: JWTPayload, secret: string, { expiresIn }?: {
20
30
  expiresIn?: string;
21
31
  }): Promise<string>;
22
- signAccessToken(payload: JWTPayload): Promise<string>;
23
- signRefreshToken(payload: JWTPayload): Promise<string>;
32
+ signAccessToken(payload: AccessTokenPayload): Promise<string>;
33
+ signRefreshToken(payload: RefreshTokenPayload): Promise<string>;
24
34
  decode(token: string): JWTPayload;
25
35
  getExpirationTime(token: string): Date;
26
36
  }
27
37
 
28
- export { JWTManager };
38
+ export { type AccessTokenPayload, JWTManager, type RefreshTokenPayload };
@@ -1,5 +1,15 @@
1
1
  import { JWTPayload } from 'jose';
2
2
 
3
+ type AccessTokenPayload = {
4
+ userId: string;
5
+ role: string;
6
+ name: string;
7
+ };
8
+ type RefreshTokenPayload = {
9
+ userId: string;
10
+ role: string;
11
+ name: string;
12
+ };
3
13
  declare class JWTManager {
4
14
  siteOrigin?: string;
5
15
  accessTokenSecret: string;
@@ -14,15 +24,15 @@ declare class JWTManager {
14
24
  refreshTokenExpiresIn?: string;
15
25
  });
16
26
  verify(token: string, secret: string): Promise<JWTPayload | undefined>;
17
- verifyAccessToken(token: string): Promise<JWTPayload | undefined>;
18
- verifyRefreshToken(token: string): Promise<JWTPayload | undefined>;
27
+ verifyAccessToken(token: string): Promise<AccessTokenPayload | undefined>;
28
+ verifyRefreshToken(token: string): Promise<RefreshTokenPayload | undefined>;
19
29
  sign(payload: JWTPayload, secret: string, { expiresIn }?: {
20
30
  expiresIn?: string;
21
31
  }): Promise<string>;
22
- signAccessToken(payload: JWTPayload): Promise<string>;
23
- signRefreshToken(payload: JWTPayload): Promise<string>;
32
+ signAccessToken(payload: AccessTokenPayload): Promise<string>;
33
+ signRefreshToken(payload: RefreshTokenPayload): Promise<string>;
24
34
  decode(token: string): JWTPayload;
25
35
  getExpirationTime(token: string): Date;
26
36
  }
27
37
 
28
- export { JWTManager };
38
+ export { type AccessTokenPayload, JWTManager, type RefreshTokenPayload };
@@ -35,7 +35,7 @@ var JWTManager = class {
35
35
  accessTokenSecret,
36
36
  accessTokenExpiresIn = "10s",
37
37
  refreshTokenSecret,
38
- refreshTokenExpiresIn = "1h"
38
+ refreshTokenExpiresIn = "1y"
39
39
  }) {
40
40
  this.siteOrigin = siteOrigin;
41
41
  this.accessTokenSecret = accessTokenSecret;
@@ -52,10 +52,10 @@ var JWTManager = class {
52
52
  }
53
53
  }
54
54
  async verifyAccessToken(token) {
55
- return this.verify(token, this.accessTokenSecret);
55
+ return await this.verify(token, this.accessTokenSecret);
56
56
  }
57
57
  async verifyRefreshToken(token) {
58
- return this.verify(token, this.refreshTokenSecret);
58
+ return await this.verify(token, this.refreshTokenSecret);
59
59
  }
60
60
  async sign(payload, secret, { expiresIn } = {}) {
61
61
  let builder = new import_jose.SignJWT(payload).setProtectedHeader({ alg: "HS256", typ: "JWT" }).setIssuedAt();
@@ -11,7 +11,7 @@ var JWTManager = class {
11
11
  accessTokenSecret,
12
12
  accessTokenExpiresIn = "10s",
13
13
  refreshTokenSecret,
14
- refreshTokenExpiresIn = "1h"
14
+ refreshTokenExpiresIn = "1y"
15
15
  }) {
16
16
  this.siteOrigin = siteOrigin;
17
17
  this.accessTokenSecret = accessTokenSecret;
@@ -28,10 +28,10 @@ var JWTManager = class {
28
28
  }
29
29
  }
30
30
  async verifyAccessToken(token) {
31
- return this.verify(token, this.accessTokenSecret);
31
+ return await this.verify(token, this.accessTokenSecret);
32
32
  }
33
33
  async verifyRefreshToken(token) {
34
- return this.verify(token, this.refreshTokenSecret);
34
+ return await this.verify(token, this.refreshTokenSecret);
35
35
  }
36
36
  async sign(payload, secret, { expiresIn } = {}) {
37
37
  let builder = new SignJWT(payload).setProtectedHeader({ alg: "HS256", typ: "JWT" }).setIssuedAt();
@@ -1,8 +1,8 @@
1
1
  import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.mjs';
2
2
  import './auth_service.mjs';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import './jwt_manager.mjs';
5
+ import 'react-router';
6
6
  import '../file/object_storage.mjs';
7
7
  import '@aws-sdk/client-s3';
8
8
  import './auth_repository.mjs';
@@ -1,8 +1,8 @@
1
1
  import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.js';
2
2
  import './auth_service.js';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import './jwt_manager.js';
5
+ import 'react-router';
6
6
  import '../file/object_storage.js';
7
7
  import '@aws-sdk/client-s3';
8
8
  import './auth_repository.js';
@@ -1,7 +1,7 @@
1
1
  import { AuthService } from './auth_service.mjs';
2
2
  import 'jose';
3
- import 'react-router';
4
3
  import './jwt_manager.mjs';
4
+ import 'react-router';
5
5
  import '../file/object_storage.mjs';
6
6
  import '@aws-sdk/client-s3';
7
7
  import './auth_repository.mjs';
@@ -1,7 +1,7 @@
1
1
  import { AuthService } from './auth_service.js';
2
2
  import 'jose';
3
- import 'react-router';
4
3
  import './jwt_manager.js';
4
+ import 'react-router';
5
5
  import '../file/object_storage.js';
6
6
  import '@aws-sdk/client-s3';
7
7
  import './auth_repository.js';
@@ -1,16 +1,16 @@
1
1
  import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
2
2
  import { AuthService } from './auth_service.mjs';
3
- import { JWTPayload } from 'jose';
4
- import './jwt_manager.mjs';
3
+ import { AccessTokenPayload } from './jwt_manager.mjs';
4
+ import 'jose';
5
5
  import '../file/object_storage.mjs';
6
6
  import '@aws-sdk/client-s3';
7
7
  import './auth_repository.mjs';
8
8
 
9
9
  type Handler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (arg: T) => Promise<unknown> | unknown;
10
- type InputFN = (auth?: JWTPayload) => Handler<LoaderFunctionArgs> | Handler<ActionFunctionArgs>;
10
+ type InputFN = (auth?: AccessTokenPayload) => Handler<LoaderFunctionArgs> | Handler<ActionFunctionArgs>;
11
11
  type WithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (fn: InputFN) => Handler<T>;
12
12
  declare function createWithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs>({ authService }: {
13
13
  authService: AuthService;
14
- }): <THandler extends Handler<T>>(fn: (auth?: JWTPayload) => THandler) => THandler;
14
+ }): <THandler extends Handler<T>>(fn: (auth?: AccessTokenPayload) => THandler) => THandler;
15
15
 
16
16
  export { type WithAuthHandler, createWithAuthHandler };
@@ -1,16 +1,16 @@
1
1
  import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
2
2
  import { AuthService } from './auth_service.js';
3
- import { JWTPayload } from 'jose';
4
- import './jwt_manager.js';
3
+ import { AccessTokenPayload } from './jwt_manager.js';
4
+ import 'jose';
5
5
  import '../file/object_storage.js';
6
6
  import '@aws-sdk/client-s3';
7
7
  import './auth_repository.js';
8
8
 
9
9
  type Handler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (arg: T) => Promise<unknown> | unknown;
10
- type InputFN = (auth?: JWTPayload) => Handler<LoaderFunctionArgs> | Handler<ActionFunctionArgs>;
10
+ type InputFN = (auth?: AccessTokenPayload) => Handler<LoaderFunctionArgs> | Handler<ActionFunctionArgs>;
11
11
  type WithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (fn: InputFN) => Handler<T>;
12
12
  declare function createWithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs>({ authService }: {
13
13
  authService: AuthService;
14
- }): <THandler extends Handler<T>>(fn: (auth?: JWTPayload) => THandler) => THandler;
14
+ }): <THandler extends Handler<T>>(fn: (auth?: AccessTokenPayload) => THandler) => THandler;
15
15
 
16
16
  export { type WithAuthHandler, createWithAuthHandler };
@@ -30,10 +30,20 @@ function createWithAuthHandler({ authService }) {
30
30
  const res = await fn(auth)(arg);
31
31
  if (typeof res === "object" && res !== null && !Array.isArray(res)) {
32
32
  if (res instanceof Response) {
33
- if (res.status < 300 && res.body) {
34
- console.log(res.body);
35
- return res;
33
+ if (res.status < 300 && res.headers.get("Content-Type")?.includes("application/json")) {
34
+ const data = await res.json();
35
+ return new Response(
36
+ JSON.stringify({
37
+ AUTH: auth,
38
+ ...data
39
+ }),
40
+ {
41
+ status: res.status,
42
+ headers: res.headers
43
+ }
44
+ );
36
45
  }
46
+ return res;
37
47
  }
38
48
  return {
39
49
  AUTH: auth,
@@ -42,17 +52,25 @@ function createWithAuthHandler({ authService }) {
42
52
  }
43
53
  return res;
44
54
  };
45
- const accessToken = await authService.getAccessTokenFromRequest(arg.request);
55
+ const accessToken = await authService.getAccessTokenFromRequest(
56
+ arg.request
57
+ );
46
58
  if (accessToken) {
47
- const payload = await authService.jwtManager.verifyAccessToken(accessToken);
59
+ const payload = await authService.jwtManager.verifyAccessToken(
60
+ accessToken
61
+ );
48
62
  if (payload) {
49
63
  return respond(payload);
50
64
  }
51
65
  }
52
- const refreshToken = await authService.getRefreshTokenFromCookies(arg.request);
66
+ const refreshToken = await authService.getRefreshTokenFromCookies(
67
+ arg.request
68
+ );
53
69
  if (refreshToken) {
54
70
  try {
55
- const newAccessToken = await authService.refreshAccessToken(refreshToken);
71
+ const newAccessToken = await authService.refreshAccessToken(
72
+ refreshToken
73
+ );
56
74
  const setCookieHeader = await authService.getAccessTokenSetCookie(
57
75
  newAccessToken
58
76
  );
@@ -67,7 +85,9 @@ function createWithAuthHandler({ authService }) {
67
85
  if (e instanceof Error) {
68
86
  console.log(e.message);
69
87
  }
70
- const setCookieHeader = await authService.getRefreshTokenSetCookie(null);
88
+ const setCookieHeader = await authService.getRefreshTokenSetCookie(
89
+ null
90
+ );
71
91
  const headers = new Headers();
72
92
  headers.append("Set-Cookie", setCookieHeader);
73
93
  headers.append("Location", arg.request.url);
@@ -6,10 +6,20 @@ function createWithAuthHandler({ authService }) {
6
6
  const res = await fn(auth)(arg);
7
7
  if (typeof res === "object" && res !== null && !Array.isArray(res)) {
8
8
  if (res instanceof Response) {
9
- if (res.status < 300 && res.body) {
10
- console.log(res.body);
11
- return res;
9
+ if (res.status < 300 && res.headers.get("Content-Type")?.includes("application/json")) {
10
+ const data = await res.json();
11
+ return new Response(
12
+ JSON.stringify({
13
+ AUTH: auth,
14
+ ...data
15
+ }),
16
+ {
17
+ status: res.status,
18
+ headers: res.headers
19
+ }
20
+ );
12
21
  }
22
+ return res;
13
23
  }
14
24
  return {
15
25
  AUTH: auth,
@@ -18,17 +28,25 @@ function createWithAuthHandler({ authService }) {
18
28
  }
19
29
  return res;
20
30
  };
21
- const accessToken = await authService.getAccessTokenFromRequest(arg.request);
31
+ const accessToken = await authService.getAccessTokenFromRequest(
32
+ arg.request
33
+ );
22
34
  if (accessToken) {
23
- const payload = await authService.jwtManager.verifyAccessToken(accessToken);
35
+ const payload = await authService.jwtManager.verifyAccessToken(
36
+ accessToken
37
+ );
24
38
  if (payload) {
25
39
  return respond(payload);
26
40
  }
27
41
  }
28
- const refreshToken = await authService.getRefreshTokenFromCookies(arg.request);
42
+ const refreshToken = await authService.getRefreshTokenFromCookies(
43
+ arg.request
44
+ );
29
45
  if (refreshToken) {
30
46
  try {
31
- const newAccessToken = await authService.refreshAccessToken(refreshToken);
47
+ const newAccessToken = await authService.refreshAccessToken(
48
+ refreshToken
49
+ );
32
50
  const setCookieHeader = await authService.getAccessTokenSetCookie(
33
51
  newAccessToken
34
52
  );
@@ -43,7 +61,9 @@ function createWithAuthHandler({ authService }) {
43
61
  if (e instanceof Error) {
44
62
  console.log(e.message);
45
63
  }
46
- const setCookieHeader = await authService.getRefreshTokenSetCookie(null);
64
+ const setCookieHeader = await authService.getRefreshTokenSetCookie(
65
+ null
66
+ );
47
67
  const headers = new Headers();
48
68
  headers.append("Set-Cookie", setCookieHeader);
49
69
  headers.append("Location", arg.request.url);
@@ -1,8 +1,8 @@
1
1
  import { AuthService } from '../../auth/auth_service.mjs';
2
2
  import { FileRepository } from '../file_repository.mjs';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../../auth/jwt_manager.mjs';
5
+ import 'react-router';
6
6
  import '../object_storage.mjs';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../../auth/auth_repository.mjs';
@@ -1,8 +1,8 @@
1
1
  import { AuthService } from '../../auth/auth_service.js';
2
2
  import { FileRepository } from '../file_repository.js';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../../auth/jwt_manager.js';
5
+ import 'react-router';
6
6
  import '../object_storage.js';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../../auth/auth_repository.js';
@@ -1,8 +1,8 @@
1
1
  import { AuthService } from '../../auth/auth_service.mjs';
2
2
  import { FileService } from '../file_service.mjs';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../../auth/jwt_manager.mjs';
5
+ import 'react-router';
6
6
  import '../object_storage.mjs';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../../auth/auth_repository.mjs';
@@ -1,8 +1,8 @@
1
1
  import { AuthService } from '../../auth/auth_service.js';
2
2
  import { FileService } from '../file_service.js';
3
3
  import 'jose';
4
- import 'react-router';
5
4
  import '../../auth/jwt_manager.js';
5
+ import 'react-router';
6
6
  import '../object_storage.js';
7
7
  import '@aws-sdk/client-s3';
8
8
  import '../../auth/auth_repository.js';
package/package.json CHANGED
@@ -1,85 +1,85 @@
1
1
  {
2
- "name": "dn-react-router-toolkit",
3
- "version": "0.2.1",
4
- "types": "./dist/index.d.ts",
5
- "main": "./dist/index.mjs",
6
- "module": "./dist/index.js",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/index.d.ts",
10
- "import": "./dist/index.mjs",
11
- "require": "./dist/index.js"
12
- },
13
- "./auth/*": {
14
- "types": "./dist/auth/*.d.ts",
15
- "import": "./dist/auth/*.mjs",
16
- "require": "./dist/auth/*.js"
17
- },
18
- "./file/*": {
19
- "types": "./dist/file/*.d.ts",
20
- "import": "./dist/file/*.mjs",
21
- "require": "./dist/file/*.js"
22
- },
23
- "./route/*": {
24
- "types": "./dist/route/*.d.ts",
25
- "import": "./dist/route/*.mjs",
26
- "require": "./dist/route/*.js"
27
- },
28
- "./components/*": {
29
- "types": "./dist/components/*.d.ts",
30
- "import": "./dist/components/*.mjs",
31
- "require": "./dist/components/*.js"
32
- },
33
- "./http/*": {
34
- "types": "./dist/http/*.d.ts",
35
- "import": "./dist/http/*.mjs",
36
- "require": "./dist/http/*.js"
37
- },
38
- "./seo/*": {
39
- "types": "./dist/seo/*.d.ts",
40
- "import": "./dist/seo/*.mjs",
41
- "require": "./dist/seo/*.js"
42
- }
2
+ "name": "dn-react-router-toolkit",
3
+ "version": "0.2.3",
4
+ "types": "./dist/index.d.ts",
5
+ "main": "./dist/index.mjs",
6
+ "module": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js"
43
12
  },
44
- "scripts": {
45
- "build": "tsup",
46
- "dev": "tsup --watch"
13
+ "./auth/*": {
14
+ "types": "./dist/auth/*.d.ts",
15
+ "import": "./dist/auth/*.mjs",
16
+ "require": "./dist/auth/*.js"
47
17
  },
48
- "repository": {
49
- "type": "git",
50
- "url": "git+https://github.com/dndnsoft/dn-react-router-toolkit.git"
18
+ "./file/*": {
19
+ "types": "./dist/file/*.d.ts",
20
+ "import": "./dist/file/*.mjs",
21
+ "require": "./dist/file/*.js"
51
22
  },
52
- "author": "",
53
- "license": "MIT",
54
- "bugs": {
55
- "url": "https://github.com/dndnsoft/dn-react-router-toolkit/issues"
23
+ "./route/*": {
24
+ "types": "./dist/route/*.d.ts",
25
+ "import": "./dist/route/*.mjs",
26
+ "require": "./dist/route/*.js"
56
27
  },
57
- "homepage": "https://github.com/dndnsoft/dn-react-router-toolkit#readme",
58
- "description": "",
59
- "devDependencies": {
60
- "@types/node": "^24.10.1",
61
- "@types/nodemailer": "^7.0.4",
62
- "@types/react": "^19",
63
- "@types/react-dom": "^19",
64
- "rimraf": "^6.0.1",
65
- "schema-dts": "^1.1.5",
66
- "tsup": "^8.5.1",
67
- "typescript": "^5.7.3"
28
+ "./components/*": {
29
+ "types": "./dist/components/*.d.ts",
30
+ "import": "./dist/components/*.mjs",
31
+ "require": "./dist/components/*.js"
68
32
  },
69
- "dependencies": {
70
- "@aws-sdk/client-s3": "^3.940.0",
71
- "@aws-sdk/s3-request-presigner": "^3.940.0",
72
- "bcryptjs": "^3.0.3",
73
- "jose": "^6.1.2",
74
- "moment-timezone": "^0.6.0",
75
- "nodemailer": "^7.0.11",
76
- "react-icons": "^5.5.0",
77
- "uuid": "^13.0.0"
33
+ "./http/*": {
34
+ "types": "./dist/http/*.d.ts",
35
+ "import": "./dist/http/*.mjs",
36
+ "require": "./dist/http/*.js"
78
37
  },
79
- "peerDependencies": {
80
- "drizzle-orm": "^0.44",
81
- "react": "^19",
82
- "react-dom": "^19",
83
- "react-router": "^7"
38
+ "./seo/*": {
39
+ "types": "./dist/seo/*.d.ts",
40
+ "import": "./dist/seo/*.mjs",
41
+ "require": "./dist/seo/*.js"
84
42
  }
43
+ },
44
+ "scripts": {
45
+ "build": "tsup",
46
+ "dev": "tsup --watch"
47
+ },
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/dndnsoft/dn-react-router-toolkit.git"
51
+ },
52
+ "author": "",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/dndnsoft/dn-react-router-toolkit/issues"
56
+ },
57
+ "homepage": "https://github.com/dndnsoft/dn-react-router-toolkit#readme",
58
+ "description": "",
59
+ "devDependencies": {
60
+ "@types/node": "^24.10.1",
61
+ "@types/nodemailer": "^7.0.4",
62
+ "@types/react": "^19",
63
+ "@types/react-dom": "^19",
64
+ "rimraf": "^6.0.1",
65
+ "schema-dts": "^1.1.5",
66
+ "tsup": "^8.5.1",
67
+ "typescript": "^5.7.3"
68
+ },
69
+ "dependencies": {
70
+ "@aws-sdk/client-s3": "^3.940.0",
71
+ "@aws-sdk/s3-request-presigner": "^3.940.0",
72
+ "bcryptjs": "^3.0.3",
73
+ "jose": "^6.1.2",
74
+ "moment-timezone": "^0.6.0",
75
+ "nodemailer": "^7.0.11",
76
+ "react-icons": "^5.5.0",
77
+ "uuid": "^13.0.0"
78
+ },
79
+ "peerDependencies": {
80
+ "drizzle-orm": "^0.44",
81
+ "react": "^19",
82
+ "react-dom": "^19",
83
+ "react-router": "^7"
84
+ }
85
85
  }