dn-react-router-toolkit 0.2.2 → 0.2.4
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/auth/apple_auth.d.mts +1 -1
- package/dist/auth/apple_auth.d.ts +1 -1
- package/dist/auth/auth_service.d.mts +3 -3
- package/dist/auth/auth_service.d.ts +3 -3
- package/dist/auth/client/provider.d.mts +6 -8
- package/dist/auth/client/provider.d.ts +6 -8
- package/dist/auth/client/provider.js +7 -5
- package/dist/auth/client/provider.mjs +7 -5
- package/dist/auth/google_auth.d.mts +1 -1
- package/dist/auth/google_auth.d.ts +1 -1
- package/dist/auth/handlers/find_auth.d.mts +1 -1
- package/dist/auth/handlers/find_auth.d.ts +1 -1
- package/dist/auth/handlers/login.d.mts +1 -1
- package/dist/auth/handlers/login.d.ts +1 -1
- package/dist/auth/handlers/login_with_thirdparty.d.mts +1 -1
- package/dist/auth/handlers/login_with_thirdparty.d.ts +1 -1
- package/dist/auth/handlers/logout.d.mts +1 -1
- package/dist/auth/handlers/logout.d.ts +1 -1
- package/dist/auth/handlers/refresh.d.mts +1 -1
- package/dist/auth/handlers/refresh.d.ts +1 -1
- package/dist/auth/handlers/signup.d.mts +1 -1
- package/dist/auth/handlers/signup.d.ts +1 -1
- package/dist/auth/handlers/signup_with_thirdparty.d.mts +1 -1
- package/dist/auth/handlers/signup_with_thirdparty.d.ts +1 -1
- package/dist/auth/handlers/thirdparty_auth_callback.d.mts +1 -1
- package/dist/auth/handlers/thirdparty_auth_callback.d.ts +1 -1
- package/dist/auth/jwt_manager.d.mts +15 -5
- package/dist/auth/jwt_manager.d.ts +15 -5
- package/dist/auth/jwt_manager.js +4 -4
- package/dist/auth/jwt_manager.mjs +4 -4
- package/dist/auth/kakao_auth.d.mts +1 -1
- package/dist/auth/kakao_auth.d.ts +1 -1
- package/dist/auth/thirdparty_auth.d.mts +1 -1
- package/dist/auth/thirdparty_auth.d.ts +1 -1
- package/dist/auth/with_auth.d.mts +4 -4
- package/dist/auth/with_auth.d.ts +4 -4
- package/dist/auth/with_auth.js +25 -12
- package/dist/auth/with_auth.mjs +25 -12
- package/dist/file/handlers/delete_file.d.mts +1 -1
- package/dist/file/handlers/delete_file.d.ts +1 -1
- package/dist/file/handlers/upload_file.d.mts +1 -1
- package/dist/file/handlers/upload_file.d.ts +1 -1
- 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<
|
|
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<
|
|
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,21 +1,19 @@
|
|
|
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
|
-
|
|
6
|
-
};
|
|
7
|
-
login: (id: string, password: string) => Promise<void>;
|
|
6
|
+
auth: AccessTokenPayload | undefined;
|
|
7
|
+
login: (id: string, password: string) => Promise<AccessTokenPayload>;
|
|
8
8
|
loginWithGoogle: (redirectUrl?: string) => Promise<void>;
|
|
9
9
|
logout: () => Promise<void>;
|
|
10
|
-
signup: (email: string, password: string, passwordConfirm: string) => Promise<
|
|
11
|
-
userId: string;
|
|
12
|
-
}>;
|
|
10
|
+
signup: (email: string, password: string, passwordConfirm: string) => Promise<AccessTokenPayload>;
|
|
13
11
|
requestResetPassword: (email: string) => Promise<boolean>;
|
|
14
12
|
resetPassword: (token: string, password: string, passwordConfirm: string) => Promise<boolean>;
|
|
15
13
|
};
|
|
16
14
|
declare const AuthContext: React.Context<AuthContextValue>;
|
|
17
15
|
declare const useAuth: () => AuthContextValue;
|
|
18
|
-
declare function AuthProvider({ children, googleAuth }: {
|
|
16
|
+
declare function AuthProvider({ children, googleAuth, }: {
|
|
19
17
|
children: React.ReactNode;
|
|
20
18
|
googleAuth?: {
|
|
21
19
|
googleClientId: string;
|
|
@@ -1,21 +1,19 @@
|
|
|
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
|
-
|
|
6
|
-
};
|
|
7
|
-
login: (id: string, password: string) => Promise<void>;
|
|
6
|
+
auth: AccessTokenPayload | undefined;
|
|
7
|
+
login: (id: string, password: string) => Promise<AccessTokenPayload>;
|
|
8
8
|
loginWithGoogle: (redirectUrl?: string) => Promise<void>;
|
|
9
9
|
logout: () => Promise<void>;
|
|
10
|
-
signup: (email: string, password: string, passwordConfirm: string) => Promise<
|
|
11
|
-
userId: string;
|
|
12
|
-
}>;
|
|
10
|
+
signup: (email: string, password: string, passwordConfirm: string) => Promise<AccessTokenPayload>;
|
|
13
11
|
requestResetPassword: (email: string) => Promise<boolean>;
|
|
14
12
|
resetPassword: (token: string, password: string, passwordConfirm: string) => Promise<boolean>;
|
|
15
13
|
};
|
|
16
14
|
declare const AuthContext: React.Context<AuthContextValue>;
|
|
17
15
|
declare const useAuth: () => AuthContextValue;
|
|
18
|
-
declare function AuthProvider({ children, googleAuth }: {
|
|
16
|
+
declare function AuthProvider({ children, googleAuth, }: {
|
|
19
17
|
children: React.ReactNode;
|
|
20
18
|
googleAuth?: {
|
|
21
19
|
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({
|
|
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)();
|
|
@@ -54,12 +57,11 @@ function AuthProvider({ children, googleAuth }) {
|
|
|
54
57
|
},
|
|
55
58
|
body: JSON.stringify({ id, password })
|
|
56
59
|
});
|
|
57
|
-
if (res.ok) {
|
|
58
|
-
navigate("/");
|
|
59
|
-
} else {
|
|
60
|
+
if (!res.ok) {
|
|
60
61
|
const { message } = await res.json();
|
|
61
|
-
|
|
62
|
+
throw new Error(message);
|
|
62
63
|
}
|
|
64
|
+
return res.json();
|
|
63
65
|
};
|
|
64
66
|
const loginWithGoogle = async (redirectUrl = "/") => {
|
|
65
67
|
if (!googleAuth) {
|
|
@@ -6,7 +6,10 @@ var AuthContext = createContext({});
|
|
|
6
6
|
var useAuth = () => {
|
|
7
7
|
return useContext(AuthContext);
|
|
8
8
|
};
|
|
9
|
-
function AuthProvider({
|
|
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();
|
|
@@ -18,12 +21,11 @@ function AuthProvider({ children, googleAuth }) {
|
|
|
18
21
|
},
|
|
19
22
|
body: JSON.stringify({ id, password })
|
|
20
23
|
});
|
|
21
|
-
if (res.ok) {
|
|
22
|
-
navigate("/");
|
|
23
|
-
} else {
|
|
24
|
+
if (!res.ok) {
|
|
24
25
|
const { message } = await res.json();
|
|
25
|
-
|
|
26
|
+
throw new Error(message);
|
|
26
27
|
}
|
|
28
|
+
return res.json();
|
|
27
29
|
};
|
|
28
30
|
const loginWithGoogle = async (redirectUrl = "/") => {
|
|
29
31
|
if (!googleAuth) {
|
|
@@ -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,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,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<
|
|
18
|
-
verifyRefreshToken(token: string): Promise<
|
|
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:
|
|
23
|
-
signRefreshToken(payload:
|
|
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<
|
|
18
|
-
verifyRefreshToken(token: string): Promise<
|
|
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:
|
|
23
|
-
signRefreshToken(payload:
|
|
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 };
|
package/dist/auth/jwt_manager.js
CHANGED
|
@@ -33,9 +33,9 @@ var JWTManager = class {
|
|
|
33
33
|
constructor({
|
|
34
34
|
siteOrigin,
|
|
35
35
|
accessTokenSecret,
|
|
36
|
-
accessTokenExpiresIn = "
|
|
36
|
+
accessTokenExpiresIn = "1m",
|
|
37
37
|
refreshTokenSecret,
|
|
38
|
-
refreshTokenExpiresIn = "
|
|
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();
|
|
@@ -9,9 +9,9 @@ var JWTManager = class {
|
|
|
9
9
|
constructor({
|
|
10
10
|
siteOrigin,
|
|
11
11
|
accessTokenSecret,
|
|
12
|
-
accessTokenExpiresIn = "
|
|
12
|
+
accessTokenExpiresIn = "1m",
|
|
13
13
|
refreshTokenSecret,
|
|
14
|
-
refreshTokenExpiresIn = "
|
|
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,16 +1,16 @@
|
|
|
1
1
|
import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
|
|
2
2
|
import { AuthService } from './auth_service.mjs';
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
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?:
|
|
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?:
|
|
14
|
+
}): <THandler extends Handler<T>>(fn: (auth?: AccessTokenPayload) => THandler) => THandler;
|
|
15
15
|
|
|
16
16
|
export { type WithAuthHandler, createWithAuthHandler };
|
package/dist/auth/with_auth.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
|
|
2
2
|
import { AuthService } from './auth_service.js';
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
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?:
|
|
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?:
|
|
14
|
+
}): <THandler extends Handler<T>>(fn: (auth?: AccessTokenPayload) => THandler) => THandler;
|
|
15
15
|
|
|
16
16
|
export { type WithAuthHandler, createWithAuthHandler };
|
package/dist/auth/with_auth.js
CHANGED
|
@@ -32,13 +32,16 @@ function createWithAuthHandler({ authService }) {
|
|
|
32
32
|
if (res instanceof Response) {
|
|
33
33
|
if (res.status < 300 && res.headers.get("Content-Type")?.includes("application/json")) {
|
|
34
34
|
const data = await res.json();
|
|
35
|
-
return new Response(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
return new Response(
|
|
36
|
+
JSON.stringify({
|
|
37
|
+
AUTH: auth,
|
|
38
|
+
...data
|
|
39
|
+
}),
|
|
40
|
+
{
|
|
41
|
+
status: res.status,
|
|
42
|
+
headers: res.headers
|
|
43
|
+
}
|
|
44
|
+
);
|
|
42
45
|
}
|
|
43
46
|
return res;
|
|
44
47
|
}
|
|
@@ -49,17 +52,25 @@ function createWithAuthHandler({ authService }) {
|
|
|
49
52
|
}
|
|
50
53
|
return res;
|
|
51
54
|
};
|
|
52
|
-
const accessToken = await authService.getAccessTokenFromRequest(
|
|
55
|
+
const accessToken = await authService.getAccessTokenFromRequest(
|
|
56
|
+
arg.request
|
|
57
|
+
);
|
|
53
58
|
if (accessToken) {
|
|
54
|
-
const payload = await authService.jwtManager.verifyAccessToken(
|
|
59
|
+
const payload = await authService.jwtManager.verifyAccessToken(
|
|
60
|
+
accessToken
|
|
61
|
+
);
|
|
55
62
|
if (payload) {
|
|
56
63
|
return respond(payload);
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
|
-
const refreshToken = await authService.getRefreshTokenFromCookies(
|
|
66
|
+
const refreshToken = await authService.getRefreshTokenFromCookies(
|
|
67
|
+
arg.request
|
|
68
|
+
);
|
|
60
69
|
if (refreshToken) {
|
|
61
70
|
try {
|
|
62
|
-
const newAccessToken = await authService.refreshAccessToken(
|
|
71
|
+
const newAccessToken = await authService.refreshAccessToken(
|
|
72
|
+
refreshToken
|
|
73
|
+
);
|
|
63
74
|
const setCookieHeader = await authService.getAccessTokenSetCookie(
|
|
64
75
|
newAccessToken
|
|
65
76
|
);
|
|
@@ -74,7 +85,9 @@ function createWithAuthHandler({ authService }) {
|
|
|
74
85
|
if (e instanceof Error) {
|
|
75
86
|
console.log(e.message);
|
|
76
87
|
}
|
|
77
|
-
const setCookieHeader = await authService.getRefreshTokenSetCookie(
|
|
88
|
+
const setCookieHeader = await authService.getRefreshTokenSetCookie(
|
|
89
|
+
null
|
|
90
|
+
);
|
|
78
91
|
const headers = new Headers();
|
|
79
92
|
headers.append("Set-Cookie", setCookieHeader);
|
|
80
93
|
headers.append("Location", arg.request.url);
|
package/dist/auth/with_auth.mjs
CHANGED
|
@@ -8,13 +8,16 @@ function createWithAuthHandler({ authService }) {
|
|
|
8
8
|
if (res instanceof Response) {
|
|
9
9
|
if (res.status < 300 && res.headers.get("Content-Type")?.includes("application/json")) {
|
|
10
10
|
const data = await res.json();
|
|
11
|
-
return new Response(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
return new Response(
|
|
12
|
+
JSON.stringify({
|
|
13
|
+
AUTH: auth,
|
|
14
|
+
...data
|
|
15
|
+
}),
|
|
16
|
+
{
|
|
17
|
+
status: res.status,
|
|
18
|
+
headers: res.headers
|
|
19
|
+
}
|
|
20
|
+
);
|
|
18
21
|
}
|
|
19
22
|
return res;
|
|
20
23
|
}
|
|
@@ -25,17 +28,25 @@ function createWithAuthHandler({ authService }) {
|
|
|
25
28
|
}
|
|
26
29
|
return res;
|
|
27
30
|
};
|
|
28
|
-
const accessToken = await authService.getAccessTokenFromRequest(
|
|
31
|
+
const accessToken = await authService.getAccessTokenFromRequest(
|
|
32
|
+
arg.request
|
|
33
|
+
);
|
|
29
34
|
if (accessToken) {
|
|
30
|
-
const payload = await authService.jwtManager.verifyAccessToken(
|
|
35
|
+
const payload = await authService.jwtManager.verifyAccessToken(
|
|
36
|
+
accessToken
|
|
37
|
+
);
|
|
31
38
|
if (payload) {
|
|
32
39
|
return respond(payload);
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
|
-
const refreshToken = await authService.getRefreshTokenFromCookies(
|
|
42
|
+
const refreshToken = await authService.getRefreshTokenFromCookies(
|
|
43
|
+
arg.request
|
|
44
|
+
);
|
|
36
45
|
if (refreshToken) {
|
|
37
46
|
try {
|
|
38
|
-
const newAccessToken = await authService.refreshAccessToken(
|
|
47
|
+
const newAccessToken = await authService.refreshAccessToken(
|
|
48
|
+
refreshToken
|
|
49
|
+
);
|
|
39
50
|
const setCookieHeader = await authService.getAccessTokenSetCookie(
|
|
40
51
|
newAccessToken
|
|
41
52
|
);
|
|
@@ -50,7 +61,9 @@ function createWithAuthHandler({ authService }) {
|
|
|
50
61
|
if (e instanceof Error) {
|
|
51
62
|
console.log(e.message);
|
|
52
63
|
}
|
|
53
|
-
const setCookieHeader = await authService.getRefreshTokenSetCookie(
|
|
64
|
+
const setCookieHeader = await authService.getRefreshTokenSetCookie(
|
|
65
|
+
null
|
|
66
|
+
);
|
|
54
67
|
const headers = new Headers();
|
|
55
68
|
headers.append("Set-Cookie", setCookieHeader);
|
|
56
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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.4",
|
|
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
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
13
|
+
"./auth/*": {
|
|
14
|
+
"types": "./dist/auth/*.d.ts",
|
|
15
|
+
"import": "./dist/auth/*.mjs",
|
|
16
|
+
"require": "./dist/auth/*.js"
|
|
47
17
|
},
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
18
|
+
"./file/*": {
|
|
19
|
+
"types": "./dist/file/*.d.ts",
|
|
20
|
+
"import": "./dist/file/*.mjs",
|
|
21
|
+
"require": "./dist/file/*.js"
|
|
51
22
|
},
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
23
|
+
"./route/*": {
|
|
24
|
+
"types": "./dist/route/*.d.ts",
|
|
25
|
+
"import": "./dist/route/*.mjs",
|
|
26
|
+
"require": "./dist/route/*.js"
|
|
56
27
|
},
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
}
|