adminforth 1.1.88 → 1.1.89

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/auth.ts CHANGED
@@ -84,7 +84,6 @@ class AdminForthAuth {
84
84
  return null;
85
85
  }
86
86
  const { pk, t } = decoded;
87
- process.env.HEAVY_DEBUG && console.log('🪲Decoded token:', decoded, 'orig token', jwtToken);
88
87
  if (t !== mustHaveType) {
89
88
  console.error(`Invalid token type during verification: ${t}, must be ${mustHaveType}`);
90
89
  return null;
package/dist/auth.js CHANGED
@@ -76,7 +76,6 @@ class AdminForthAuth {
76
76
  return null;
77
77
  }
78
78
  const { pk, t } = decoded;
79
- process.env.HEAVY_DEBUG && console.log('🪲Decoded token:', decoded, 'orig token', jwtToken);
80
79
  if (t !== mustHaveType) {
81
80
  console.error(`Invalid token type during verification: ${t}, must be ${mustHaveType}`);
82
81
  return null;
@@ -28,13 +28,13 @@ function parseExpressCookie(req) {
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
29
  const cookies = req.headers.cookie;
30
30
  if (!cookies) {
31
- return {};
31
+ return [];
32
32
  }
33
33
  const parts = cookies.split('; ');
34
- const result = {};
34
+ const result = [];
35
35
  parts.forEach(part => {
36
36
  const [key, value] = part.split('=');
37
- result[key] = value;
37
+ result.push({ key, value });
38
38
  });
39
39
  return result;
40
40
  });
@@ -143,8 +143,18 @@ class ExpressServer {
143
143
  }
144
144
  authorize(handler) {
145
145
  return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
146
+ var _a;
146
147
  const cookies = yield parseExpressCookie(req);
147
- const jwt = cookies['adminforth_jwt'];
148
+ // check if multiple adminforth_jwt providerd and show warning
149
+ const jwts = cookies.filter(({ key }) => key === 'adminforth_jwt');
150
+ if (jwts.length > 1) {
151
+ console.error('Multiple adminforth_jwt cookies provided');
152
+ jwts.forEach(({ key }) => {
153
+ res.setHeader('Set-Cookie', `${key}=; HttpOnly; SameSite=Strict; Expires=${new Date(0).toUTCString()}`);
154
+ });
155
+ res.status(401).send(`Unauthorized by AdminForth. Too many JWT cookies found (${jwts.length} instead of 1). Expected to get only one cookie with name 'adminforth_jwt'.`);
156
+ }
157
+ const jwt = (_a = jwts[0]) === null || _a === void 0 ? void 0 : _a.value;
148
158
  if (!jwt) {
149
159
  res.status(401).send('Unauthorized by AdminForth');
150
160
  return;
@@ -17,7 +17,6 @@ export async function callApi({path, method, body=undefined}: {
17
17
  },
18
18
  body: JSON.stringify(body),
19
19
  };
20
- console.log('calling api, import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH', import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH);
21
20
  const fullPath = `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH || ''}${path}`;
22
21
  const r = await fetch(fullPath, options);
23
22
  if (r.status == 401 ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.1.88",
3
+ "version": "1.1.89",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,16 +20,21 @@ async function proxyTo(url, res) {
20
20
  actual.body.pipe(res);
21
21
  }
22
22
 
23
- async function parseExpressCookie(req) {
23
+ async function parseExpressCookie(req): Promise<
24
+ Array<{
25
+ key: string,
26
+ value: string
27
+ }>
28
+ > {
24
29
  const cookies = req.headers.cookie;
25
30
  if (!cookies) {
26
- return {};
31
+ return [];
27
32
  }
28
33
  const parts = cookies.split('; ');
29
- const result = {};
34
+ const result = [];
30
35
  parts.forEach(part => {
31
36
  const [key, value] = part.split('=');
32
- result[key] = value;
37
+ result.push({key, value});
33
38
  });
34
39
  return result;
35
40
  }
@@ -152,7 +157,19 @@ class ExpressServer implements ExpressHttpServer {
152
157
  authorize(handler) {
153
158
  return async (req, res, next) => {
154
159
  const cookies = await parseExpressCookie(req);
155
- const jwt = cookies['adminforth_jwt'];
160
+
161
+ // check if multiple adminforth_jwt providerd and show warning
162
+ const jwts = cookies.filter(({key}) => key === 'adminforth_jwt');
163
+ if (jwts.length > 1) {
164
+ console.error('Multiple adminforth_jwt cookies provided');
165
+ jwts.forEach(({key}) => {
166
+ res.setHeader('Set-Cookie', `${key}=; HttpOnly; SameSite=Strict; Expires=${new Date(0).toUTCString()}`);
167
+ });
168
+ res.status(401).send(`Unauthorized by AdminForth. Too many JWT cookies found (${jwts.length} instead of 1). Expected to get only one cookie with name 'adminforth_jwt'.`);
169
+ }
170
+
171
+ const jwt = jwts[0]?.value;
172
+
156
173
  if (!jwt) {
157
174
  res.status(401).send('Unauthorized by AdminForth');
158
175
  return
package/spa/src/utils.ts CHANGED
@@ -17,7 +17,6 @@ export async function callApi({path, method, body=undefined}: {
17
17
  },
18
18
  body: JSON.stringify(body),
19
19
  };
20
- console.log('calling api, import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH', import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH);
21
20
  const fullPath = `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH || ''}${path}`;
22
21
  const r = await fetch(fullPath, options);
23
22
  if (r.status == 401 ) {