dn-react-router-toolkit 0.4.2 → 0.4.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/api/create_handler.js +2 -1
- package/dist/api/create_handler.mjs +2 -1
- package/dist/api/index.js +2 -1
- package/dist/api/index.mjs +2 -1
- package/dist/auth/index.d.mts +2 -1
- package/dist/auth/index.d.ts +2 -1
- package/dist/auth/index.js +57 -3
- package/dist/auth/index.mjs +55 -2
- package/dist/auth/temp_user.d.mts +5 -0
- package/dist/auth/temp_user.d.ts +5 -0
- package/dist/auth/temp_user.js +18 -0
- package/dist/auth/temp_user.mjs +0 -0
- package/dist/auth/with_auth.d.mts +7 -2
- package/dist/auth/with_auth.d.ts +7 -2
- package/dist/auth/with_auth.js +57 -3
- package/dist/auth/with_auth.mjs +55 -2
- package/package.json +59 -58
|
@@ -27,6 +27,7 @@ var import_http = require("dn-react-toolkit/http");
|
|
|
27
27
|
var import_server = require("dn-react-toolkit/auth/server");
|
|
28
28
|
|
|
29
29
|
// src/auth/with_auth.ts
|
|
30
|
+
var import_uuid = require("uuid");
|
|
30
31
|
var toResponse = (result) => {
|
|
31
32
|
if (result instanceof Response) {
|
|
32
33
|
return result;
|
|
@@ -42,7 +43,7 @@ function createWithAuthHandler({ authService }) {
|
|
|
42
43
|
};
|
|
43
44
|
const setHeader = (res, headers) => {
|
|
44
45
|
headers.forEach((value, key) => {
|
|
45
|
-
res.headers.
|
|
46
|
+
res.headers.append(key, value);
|
|
46
47
|
});
|
|
47
48
|
return res;
|
|
48
49
|
};
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from "dn-react-toolkit/auth/server";
|
|
15
15
|
|
|
16
16
|
// src/auth/with_auth.ts
|
|
17
|
+
import { v4 } from "uuid";
|
|
17
18
|
var toResponse = (result) => {
|
|
18
19
|
if (result instanceof Response) {
|
|
19
20
|
return result;
|
|
@@ -29,7 +30,7 @@ function createWithAuthHandler({ authService }) {
|
|
|
29
30
|
};
|
|
30
31
|
const setHeader = (res, headers) => {
|
|
31
32
|
headers.forEach((value, key) => {
|
|
32
|
-
res.headers.
|
|
33
|
+
res.headers.append(key, value);
|
|
33
34
|
});
|
|
34
35
|
return res;
|
|
35
36
|
};
|
package/dist/api/index.js
CHANGED
|
@@ -29,6 +29,7 @@ var import_http = require("dn-react-toolkit/http");
|
|
|
29
29
|
var import_server = require("dn-react-toolkit/auth/server");
|
|
30
30
|
|
|
31
31
|
// src/auth/with_auth.ts
|
|
32
|
+
var import_uuid = require("uuid");
|
|
32
33
|
var toResponse = (result) => {
|
|
33
34
|
if (result instanceof Response) {
|
|
34
35
|
return result;
|
|
@@ -44,7 +45,7 @@ function createWithAuthHandler({ authService }) {
|
|
|
44
45
|
};
|
|
45
46
|
const setHeader = (res, headers) => {
|
|
46
47
|
headers.forEach((value, key) => {
|
|
47
|
-
res.headers.
|
|
48
|
+
res.headers.append(key, value);
|
|
48
49
|
});
|
|
49
50
|
return res;
|
|
50
51
|
};
|
package/dist/api/index.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from "dn-react-toolkit/auth/server";
|
|
15
15
|
|
|
16
16
|
// src/auth/with_auth.ts
|
|
17
|
+
import { v4 } from "uuid";
|
|
17
18
|
var toResponse = (result) => {
|
|
18
19
|
if (result instanceof Response) {
|
|
19
20
|
return result;
|
|
@@ -29,7 +30,7 @@ function createWithAuthHandler({ authService }) {
|
|
|
29
30
|
};
|
|
30
31
|
const setHeader = (res, headers) => {
|
|
31
32
|
headers.forEach((value, key) => {
|
|
32
|
-
res.headers.
|
|
33
|
+
res.headers.append(key, value);
|
|
33
34
|
});
|
|
34
35
|
return res;
|
|
35
36
|
};
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { WithAuthHandler, createWithAuthHandler } from './with_auth.mjs';
|
|
1
|
+
export { WithAuthHandler, createWithAuthHandler, createWithTempAuthHandler } from './with_auth.mjs';
|
|
2
2
|
export { ReactRouterCookieManager } from './cookie_store.mjs';
|
|
3
|
+
export { TempUserPayload } from './temp_user.mjs';
|
|
3
4
|
import 'dn-react-toolkit/auth';
|
|
4
5
|
import 'dn-react-toolkit/auth/server';
|
|
5
6
|
import 'react-router';
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { WithAuthHandler, createWithAuthHandler } from './with_auth.js';
|
|
1
|
+
export { WithAuthHandler, createWithAuthHandler, createWithTempAuthHandler } from './with_auth.js';
|
|
2
2
|
export { ReactRouterCookieManager } from './cookie_store.js';
|
|
3
|
+
export { TempUserPayload } from './temp_user.js';
|
|
3
4
|
import 'dn-react-toolkit/auth';
|
|
4
5
|
import 'dn-react-toolkit/auth/server';
|
|
5
6
|
import 'react-router';
|
package/dist/auth/index.js
CHANGED
|
@@ -21,11 +21,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var auth_exports = {};
|
|
22
22
|
__export(auth_exports, {
|
|
23
23
|
ReactRouterCookieManager: () => ReactRouterCookieManager,
|
|
24
|
-
createWithAuthHandler: () => createWithAuthHandler
|
|
24
|
+
createWithAuthHandler: () => createWithAuthHandler,
|
|
25
|
+
createWithTempAuthHandler: () => createWithTempAuthHandler
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(auth_exports);
|
|
27
28
|
|
|
28
29
|
// src/auth/with_auth.ts
|
|
30
|
+
var import_uuid = require("uuid");
|
|
29
31
|
var toResponse = (result) => {
|
|
30
32
|
if (result instanceof Response) {
|
|
31
33
|
return result;
|
|
@@ -41,7 +43,7 @@ function createWithAuthHandler({ authService }) {
|
|
|
41
43
|
};
|
|
42
44
|
const setHeader = (res, headers) => {
|
|
43
45
|
headers.forEach((value, key) => {
|
|
44
|
-
res.headers.
|
|
46
|
+
res.headers.append(key, value);
|
|
45
47
|
});
|
|
46
48
|
return res;
|
|
47
49
|
};
|
|
@@ -88,6 +90,57 @@ function createWithAuthHandler({ authService }) {
|
|
|
88
90
|
return handler;
|
|
89
91
|
};
|
|
90
92
|
}
|
|
93
|
+
function createWithTempAuthHandler({
|
|
94
|
+
authService,
|
|
95
|
+
tempUserTokenManager,
|
|
96
|
+
tempUserCookieManager
|
|
97
|
+
}) {
|
|
98
|
+
return function(fn) {
|
|
99
|
+
const withAuthHandler = createWithAuthHandler({
|
|
100
|
+
authService
|
|
101
|
+
});
|
|
102
|
+
const handler = withAuthHandler((auth) => async (args) => {
|
|
103
|
+
if (auth) {
|
|
104
|
+
return fn(auth)(args);
|
|
105
|
+
}
|
|
106
|
+
const respond = async (auth2, headers2 = new Headers()) => {
|
|
107
|
+
const result = await fn(auth2)(args);
|
|
108
|
+
return setHeader(toResponse(result), headers2);
|
|
109
|
+
};
|
|
110
|
+
const setHeader = (res, headers2) => {
|
|
111
|
+
headers2.forEach((value, key) => {
|
|
112
|
+
res.headers.append(key, value);
|
|
113
|
+
});
|
|
114
|
+
return res;
|
|
115
|
+
};
|
|
116
|
+
const tempUserToken = await tempUserCookieManager.parse(args.request);
|
|
117
|
+
if (tempUserToken) {
|
|
118
|
+
const tempUserPayload = await tempUserTokenManager.verify(tempUserToken);
|
|
119
|
+
if (tempUserPayload) {
|
|
120
|
+
return respond(tempUserPayload);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const user = await authService.authRepository.createUser({
|
|
124
|
+
id: (0, import_uuid.v4)(),
|
|
125
|
+
role: "temp",
|
|
126
|
+
name: "\uC775\uBA85"
|
|
127
|
+
});
|
|
128
|
+
const newTempUserToken = await tempUserTokenManager.sign({
|
|
129
|
+
userId: user.id,
|
|
130
|
+
name: user.name,
|
|
131
|
+
role: user.role
|
|
132
|
+
});
|
|
133
|
+
const headers = new Headers();
|
|
134
|
+
const setCookie = await tempUserCookieManager.serialize(
|
|
135
|
+
newTempUserToken
|
|
136
|
+
);
|
|
137
|
+
headers.append("Set-Cookie", setCookie);
|
|
138
|
+
const newTempUserPayload = tempUserTokenManager.decode(newTempUserToken);
|
|
139
|
+
return respond(newTempUserPayload, headers);
|
|
140
|
+
});
|
|
141
|
+
return handler;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
91
144
|
|
|
92
145
|
// src/auth/cookie_store.ts
|
|
93
146
|
var import_react_router = require("react-router");
|
|
@@ -120,5 +173,6 @@ var ReactRouterCookieManager = class {
|
|
|
120
173
|
// Annotate the CommonJS export names for ESM import in node:
|
|
121
174
|
0 && (module.exports = {
|
|
122
175
|
ReactRouterCookieManager,
|
|
123
|
-
createWithAuthHandler
|
|
176
|
+
createWithAuthHandler,
|
|
177
|
+
createWithTempAuthHandler
|
|
124
178
|
});
|
package/dist/auth/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/auth/with_auth.ts
|
|
2
|
+
import { v4 } from "uuid";
|
|
2
3
|
var toResponse = (result) => {
|
|
3
4
|
if (result instanceof Response) {
|
|
4
5
|
return result;
|
|
@@ -14,7 +15,7 @@ function createWithAuthHandler({ authService }) {
|
|
|
14
15
|
};
|
|
15
16
|
const setHeader = (res, headers) => {
|
|
16
17
|
headers.forEach((value, key) => {
|
|
17
|
-
res.headers.
|
|
18
|
+
res.headers.append(key, value);
|
|
18
19
|
});
|
|
19
20
|
return res;
|
|
20
21
|
};
|
|
@@ -61,6 +62,57 @@ function createWithAuthHandler({ authService }) {
|
|
|
61
62
|
return handler;
|
|
62
63
|
};
|
|
63
64
|
}
|
|
65
|
+
function createWithTempAuthHandler({
|
|
66
|
+
authService,
|
|
67
|
+
tempUserTokenManager,
|
|
68
|
+
tempUserCookieManager
|
|
69
|
+
}) {
|
|
70
|
+
return function(fn) {
|
|
71
|
+
const withAuthHandler = createWithAuthHandler({
|
|
72
|
+
authService
|
|
73
|
+
});
|
|
74
|
+
const handler = withAuthHandler((auth) => async (args) => {
|
|
75
|
+
if (auth) {
|
|
76
|
+
return fn(auth)(args);
|
|
77
|
+
}
|
|
78
|
+
const respond = async (auth2, headers2 = new Headers()) => {
|
|
79
|
+
const result = await fn(auth2)(args);
|
|
80
|
+
return setHeader(toResponse(result), headers2);
|
|
81
|
+
};
|
|
82
|
+
const setHeader = (res, headers2) => {
|
|
83
|
+
headers2.forEach((value, key) => {
|
|
84
|
+
res.headers.append(key, value);
|
|
85
|
+
});
|
|
86
|
+
return res;
|
|
87
|
+
};
|
|
88
|
+
const tempUserToken = await tempUserCookieManager.parse(args.request);
|
|
89
|
+
if (tempUserToken) {
|
|
90
|
+
const tempUserPayload = await tempUserTokenManager.verify(tempUserToken);
|
|
91
|
+
if (tempUserPayload) {
|
|
92
|
+
return respond(tempUserPayload);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const user = await authService.authRepository.createUser({
|
|
96
|
+
id: v4(),
|
|
97
|
+
role: "temp",
|
|
98
|
+
name: "\uC775\uBA85"
|
|
99
|
+
});
|
|
100
|
+
const newTempUserToken = await tempUserTokenManager.sign({
|
|
101
|
+
userId: user.id,
|
|
102
|
+
name: user.name,
|
|
103
|
+
role: user.role
|
|
104
|
+
});
|
|
105
|
+
const headers = new Headers();
|
|
106
|
+
const setCookie = await tempUserCookieManager.serialize(
|
|
107
|
+
newTempUserToken
|
|
108
|
+
);
|
|
109
|
+
headers.append("Set-Cookie", setCookie);
|
|
110
|
+
const newTempUserPayload = tempUserTokenManager.decode(newTempUserToken);
|
|
111
|
+
return respond(newTempUserPayload, headers);
|
|
112
|
+
});
|
|
113
|
+
return handler;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
64
116
|
|
|
65
117
|
// src/auth/cookie_store.ts
|
|
66
118
|
import { createCookie } from "react-router";
|
|
@@ -92,5 +144,6 @@ var ReactRouterCookieManager = class {
|
|
|
92
144
|
};
|
|
93
145
|
export {
|
|
94
146
|
ReactRouterCookieManager,
|
|
95
|
-
createWithAuthHandler
|
|
147
|
+
createWithAuthHandler,
|
|
148
|
+
createWithTempAuthHandler
|
|
96
149
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/auth/temp_user.ts
|
|
17
|
+
var temp_user_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(temp_user_exports);
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AccessTokenPayload } from 'dn-react-toolkit/auth';
|
|
2
|
-
import { AuthService } from 'dn-react-toolkit/auth/server';
|
|
2
|
+
import { AuthService, JWTManager, CookieManager } from 'dn-react-toolkit/auth/server';
|
|
3
3
|
import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
|
|
4
4
|
|
|
5
5
|
type Handler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (arg: T) => Promise<unknown> | unknown;
|
|
@@ -8,5 +8,10 @@ type WithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (fn: I
|
|
|
8
8
|
declare function createWithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs>({ authService }: {
|
|
9
9
|
authService: AuthService;
|
|
10
10
|
}): <THandler extends Handler<T>>(fn: (auth?: AccessTokenPayload) => THandler) => THandler;
|
|
11
|
+
declare function createWithTempAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs>({ authService, tempUserTokenManager, tempUserCookieManager, }: {
|
|
12
|
+
authService: AuthService;
|
|
13
|
+
tempUserTokenManager: JWTManager<AccessTokenPayload>;
|
|
14
|
+
tempUserCookieManager: CookieManager;
|
|
15
|
+
}): <THandler extends Handler<T>>(fn: (auth: AccessTokenPayload) => THandler) => THandler;
|
|
11
16
|
|
|
12
|
-
export { type WithAuthHandler, createWithAuthHandler };
|
|
17
|
+
export { type WithAuthHandler, createWithAuthHandler, createWithTempAuthHandler };
|
package/dist/auth/with_auth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AccessTokenPayload } from 'dn-react-toolkit/auth';
|
|
2
|
-
import { AuthService } from 'dn-react-toolkit/auth/server';
|
|
2
|
+
import { AuthService, JWTManager, CookieManager } from 'dn-react-toolkit/auth/server';
|
|
3
3
|
import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
|
|
4
4
|
|
|
5
5
|
type Handler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (arg: T) => Promise<unknown> | unknown;
|
|
@@ -8,5 +8,10 @@ type WithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (fn: I
|
|
|
8
8
|
declare function createWithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs>({ authService }: {
|
|
9
9
|
authService: AuthService;
|
|
10
10
|
}): <THandler extends Handler<T>>(fn: (auth?: AccessTokenPayload) => THandler) => THandler;
|
|
11
|
+
declare function createWithTempAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs>({ authService, tempUserTokenManager, tempUserCookieManager, }: {
|
|
12
|
+
authService: AuthService;
|
|
13
|
+
tempUserTokenManager: JWTManager<AccessTokenPayload>;
|
|
14
|
+
tempUserCookieManager: CookieManager;
|
|
15
|
+
}): <THandler extends Handler<T>>(fn: (auth: AccessTokenPayload) => THandler) => THandler;
|
|
11
16
|
|
|
12
|
-
export { type WithAuthHandler, createWithAuthHandler };
|
|
17
|
+
export { type WithAuthHandler, createWithAuthHandler, createWithTempAuthHandler };
|
package/dist/auth/with_auth.js
CHANGED
|
@@ -20,9 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/auth/with_auth.ts
|
|
21
21
|
var with_auth_exports = {};
|
|
22
22
|
__export(with_auth_exports, {
|
|
23
|
-
createWithAuthHandler: () => createWithAuthHandler
|
|
23
|
+
createWithAuthHandler: () => createWithAuthHandler,
|
|
24
|
+
createWithTempAuthHandler: () => createWithTempAuthHandler
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(with_auth_exports);
|
|
27
|
+
var import_uuid = require("uuid");
|
|
26
28
|
var toResponse = (result) => {
|
|
27
29
|
if (result instanceof Response) {
|
|
28
30
|
return result;
|
|
@@ -38,7 +40,7 @@ function createWithAuthHandler({ authService }) {
|
|
|
38
40
|
};
|
|
39
41
|
const setHeader = (res, headers) => {
|
|
40
42
|
headers.forEach((value, key) => {
|
|
41
|
-
res.headers.
|
|
43
|
+
res.headers.append(key, value);
|
|
42
44
|
});
|
|
43
45
|
return res;
|
|
44
46
|
};
|
|
@@ -85,7 +87,59 @@ function createWithAuthHandler({ authService }) {
|
|
|
85
87
|
return handler;
|
|
86
88
|
};
|
|
87
89
|
}
|
|
90
|
+
function createWithTempAuthHandler({
|
|
91
|
+
authService,
|
|
92
|
+
tempUserTokenManager,
|
|
93
|
+
tempUserCookieManager
|
|
94
|
+
}) {
|
|
95
|
+
return function(fn) {
|
|
96
|
+
const withAuthHandler = createWithAuthHandler({
|
|
97
|
+
authService
|
|
98
|
+
});
|
|
99
|
+
const handler = withAuthHandler((auth) => async (args) => {
|
|
100
|
+
if (auth) {
|
|
101
|
+
return fn(auth)(args);
|
|
102
|
+
}
|
|
103
|
+
const respond = async (auth2, headers2 = new Headers()) => {
|
|
104
|
+
const result = await fn(auth2)(args);
|
|
105
|
+
return setHeader(toResponse(result), headers2);
|
|
106
|
+
};
|
|
107
|
+
const setHeader = (res, headers2) => {
|
|
108
|
+
headers2.forEach((value, key) => {
|
|
109
|
+
res.headers.append(key, value);
|
|
110
|
+
});
|
|
111
|
+
return res;
|
|
112
|
+
};
|
|
113
|
+
const tempUserToken = await tempUserCookieManager.parse(args.request);
|
|
114
|
+
if (tempUserToken) {
|
|
115
|
+
const tempUserPayload = await tempUserTokenManager.verify(tempUserToken);
|
|
116
|
+
if (tempUserPayload) {
|
|
117
|
+
return respond(tempUserPayload);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const user = await authService.authRepository.createUser({
|
|
121
|
+
id: (0, import_uuid.v4)(),
|
|
122
|
+
role: "temp",
|
|
123
|
+
name: "\uC775\uBA85"
|
|
124
|
+
});
|
|
125
|
+
const newTempUserToken = await tempUserTokenManager.sign({
|
|
126
|
+
userId: user.id,
|
|
127
|
+
name: user.name,
|
|
128
|
+
role: user.role
|
|
129
|
+
});
|
|
130
|
+
const headers = new Headers();
|
|
131
|
+
const setCookie = await tempUserCookieManager.serialize(
|
|
132
|
+
newTempUserToken
|
|
133
|
+
);
|
|
134
|
+
headers.append("Set-Cookie", setCookie);
|
|
135
|
+
const newTempUserPayload = tempUserTokenManager.decode(newTempUserToken);
|
|
136
|
+
return respond(newTempUserPayload, headers);
|
|
137
|
+
});
|
|
138
|
+
return handler;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
88
141
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
142
|
0 && (module.exports = {
|
|
90
|
-
createWithAuthHandler
|
|
143
|
+
createWithAuthHandler,
|
|
144
|
+
createWithTempAuthHandler
|
|
91
145
|
});
|
package/dist/auth/with_auth.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/auth/with_auth.ts
|
|
2
|
+
import { v4 } from "uuid";
|
|
2
3
|
var toResponse = (result) => {
|
|
3
4
|
if (result instanceof Response) {
|
|
4
5
|
return result;
|
|
@@ -14,7 +15,7 @@ function createWithAuthHandler({ authService }) {
|
|
|
14
15
|
};
|
|
15
16
|
const setHeader = (res, headers) => {
|
|
16
17
|
headers.forEach((value, key) => {
|
|
17
|
-
res.headers.
|
|
18
|
+
res.headers.append(key, value);
|
|
18
19
|
});
|
|
19
20
|
return res;
|
|
20
21
|
};
|
|
@@ -61,6 +62,58 @@ function createWithAuthHandler({ authService }) {
|
|
|
61
62
|
return handler;
|
|
62
63
|
};
|
|
63
64
|
}
|
|
65
|
+
function createWithTempAuthHandler({
|
|
66
|
+
authService,
|
|
67
|
+
tempUserTokenManager,
|
|
68
|
+
tempUserCookieManager
|
|
69
|
+
}) {
|
|
70
|
+
return function(fn) {
|
|
71
|
+
const withAuthHandler = createWithAuthHandler({
|
|
72
|
+
authService
|
|
73
|
+
});
|
|
74
|
+
const handler = withAuthHandler((auth) => async (args) => {
|
|
75
|
+
if (auth) {
|
|
76
|
+
return fn(auth)(args);
|
|
77
|
+
}
|
|
78
|
+
const respond = async (auth2, headers2 = new Headers()) => {
|
|
79
|
+
const result = await fn(auth2)(args);
|
|
80
|
+
return setHeader(toResponse(result), headers2);
|
|
81
|
+
};
|
|
82
|
+
const setHeader = (res, headers2) => {
|
|
83
|
+
headers2.forEach((value, key) => {
|
|
84
|
+
res.headers.append(key, value);
|
|
85
|
+
});
|
|
86
|
+
return res;
|
|
87
|
+
};
|
|
88
|
+
const tempUserToken = await tempUserCookieManager.parse(args.request);
|
|
89
|
+
if (tempUserToken) {
|
|
90
|
+
const tempUserPayload = await tempUserTokenManager.verify(tempUserToken);
|
|
91
|
+
if (tempUserPayload) {
|
|
92
|
+
return respond(tempUserPayload);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const user = await authService.authRepository.createUser({
|
|
96
|
+
id: v4(),
|
|
97
|
+
role: "temp",
|
|
98
|
+
name: "\uC775\uBA85"
|
|
99
|
+
});
|
|
100
|
+
const newTempUserToken = await tempUserTokenManager.sign({
|
|
101
|
+
userId: user.id,
|
|
102
|
+
name: user.name,
|
|
103
|
+
role: user.role
|
|
104
|
+
});
|
|
105
|
+
const headers = new Headers();
|
|
106
|
+
const setCookie = await tempUserCookieManager.serialize(
|
|
107
|
+
newTempUserToken
|
|
108
|
+
);
|
|
109
|
+
headers.append("Set-Cookie", setCookie);
|
|
110
|
+
const newTempUserPayload = tempUserTokenManager.decode(newTempUserToken);
|
|
111
|
+
return respond(newTempUserPayload, headers);
|
|
112
|
+
});
|
|
113
|
+
return handler;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
64
116
|
export {
|
|
65
|
-
createWithAuthHandler
|
|
117
|
+
createWithAuthHandler,
|
|
118
|
+
createWithTempAuthHandler
|
|
66
119
|
};
|
package/package.json
CHANGED
|
@@ -1,65 +1,66 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
"name": "dn-react-router-toolkit",
|
|
3
|
+
"version": "0.4.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"
|
|
12
|
+
},
|
|
13
|
+
"./auth": {
|
|
14
|
+
"types": "./dist/auth/index.d.ts",
|
|
15
|
+
"import": "./dist/auth/index.mjs",
|
|
16
|
+
"require": "./dist/auth/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./api": {
|
|
19
|
+
"types": "./dist/api/index.d.ts",
|
|
20
|
+
"import": "./dist/api/index.mjs",
|
|
21
|
+
"require": "./dist/api/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./client": {
|
|
24
|
+
"types": "./dist/client/index.d.ts",
|
|
25
|
+
"import": "./dist/client/index.mjs",
|
|
26
|
+
"require": "./dist/client/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./seo": {
|
|
29
|
+
"types": "./dist/seo/index.d.ts",
|
|
30
|
+
"import": "./dist/seo/index.mjs",
|
|
31
|
+
"require": "./dist/seo/index.js"
|
|
32
|
+
}
|
|
12
33
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"require": "./dist/auth/index.js"
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"dev": "tsup --watch"
|
|
17
37
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"require": "./dist/api/index.js"
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/dndnsoft/dn-react-router-toolkit.git"
|
|
22
41
|
},
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
"author": "",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/dndnsoft/dn-react-router-toolkit/issues"
|
|
27
46
|
},
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
"homepage": "https://github.com/dndnsoft/dn-react-router-toolkit#readme",
|
|
48
|
+
"description": "",
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^24.10.1",
|
|
51
|
+
"@types/react": "^19",
|
|
52
|
+
"@types/react-dom": "^19",
|
|
53
|
+
"schema-dts": "^1.1.5",
|
|
54
|
+
"tsup": "^8.5.1",
|
|
55
|
+
"typescript": "^5.7.3"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"dn-react-toolkit": "0.2.21",
|
|
59
|
+
"uuid": "^13.0.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"react": "^19",
|
|
63
|
+
"react-dom": "^19",
|
|
64
|
+
"react-router": "^7"
|
|
32
65
|
}
|
|
33
|
-
},
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build": "tsup",
|
|
36
|
-
"dev": "tsup --watch"
|
|
37
|
-
},
|
|
38
|
-
"repository": {
|
|
39
|
-
"type": "git",
|
|
40
|
-
"url": "git+https://github.com/dndnsoft/dn-react-router-toolkit.git"
|
|
41
|
-
},
|
|
42
|
-
"author": "",
|
|
43
|
-
"license": "MIT",
|
|
44
|
-
"bugs": {
|
|
45
|
-
"url": "https://github.com/dndnsoft/dn-react-router-toolkit/issues"
|
|
46
|
-
},
|
|
47
|
-
"homepage": "https://github.com/dndnsoft/dn-react-router-toolkit#readme",
|
|
48
|
-
"description": "",
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"@types/node": "^24.10.1",
|
|
51
|
-
"@types/react": "^19",
|
|
52
|
-
"@types/react-dom": "^19",
|
|
53
|
-
"schema-dts": "^1.1.5",
|
|
54
|
-
"tsup": "^8.5.1",
|
|
55
|
-
"typescript": "^5.7.3"
|
|
56
|
-
},
|
|
57
|
-
"dependencies": {
|
|
58
|
-
"dn-react-toolkit": "0.2.7"
|
|
59
|
-
},
|
|
60
|
-
"peerDependencies": {
|
|
61
|
-
"react": "^19",
|
|
62
|
-
"react-dom": "^19",
|
|
63
|
-
"react-router": "^7"
|
|
64
|
-
}
|
|
65
66
|
}
|