adminforth 1.3.25 → 1.3.26
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 +23 -2
- package/dist/auth.js +21 -2
- package/package.json +1 -1
- package/spa/src/components/Toast.vue +1 -1
- package/spa/src/views/EditView.vue +7 -0
- package/spa/src/views/ShowView.vue +1 -1
package/auth.ts
CHANGED
|
@@ -19,6 +19,23 @@ function generateSalt(length = 16) {
|
|
|
19
19
|
return crypto.randomBytes(length).toString('hex');
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
function parseTimeToSeconds(time: string): number {
|
|
23
|
+
const unit = time.slice(-1);
|
|
24
|
+
const value = parseInt(time.slice(0, -1), 10);
|
|
25
|
+
switch (unit) {
|
|
26
|
+
case 's':
|
|
27
|
+
return value;
|
|
28
|
+
case 'm':
|
|
29
|
+
return value * 60;
|
|
30
|
+
case 'h':
|
|
31
|
+
return value * 60 * 60;
|
|
32
|
+
case 'd':
|
|
33
|
+
return value * 60 * 60 * 24;
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`Invalid time unit: ${unit}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
22
39
|
class AdminForthAuth {
|
|
23
40
|
adminforth: AdminForth;
|
|
24
41
|
|
|
@@ -37,13 +54,17 @@ class AdminForthAuth {
|
|
|
37
54
|
pk: string | null
|
|
38
55
|
}) {
|
|
39
56
|
const expiresIn: string = expireInDays ? `${expireInDays}d` : (process.env.ADMINFORTH_AUTH_EXPIRESIN || '24h');
|
|
57
|
+
// might be h,m,d in string
|
|
58
|
+
const expiresInSec = parseTimeToSeconds(expiresIn);
|
|
40
59
|
|
|
41
60
|
const token = this.issueJWT({ username, pk}, 'auth', expiresIn);
|
|
42
|
-
|
|
61
|
+
const expiresCookieFormat = new Date(Date.now() + expiresInSec * 1000).toUTCString();
|
|
62
|
+
|
|
63
|
+
response.setHeader('Set-Cookie', `adminforth_jwt=${token}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=${expiresCookieFormat}`);
|
|
43
64
|
}
|
|
44
65
|
|
|
45
66
|
removeCustomCookie({response, name}) {
|
|
46
|
-
response.setHeader('Set-Cookie', `
|
|
67
|
+
response.setHeader('Set-Cookie', `adminforth_${name}=; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=Thu, 01 Jan 1970 00:00:00 GMT`);
|
|
47
68
|
}
|
|
48
69
|
|
|
49
70
|
setCustomCookie({ response, payload }: {
|
package/dist/auth.js
CHANGED
|
@@ -23,6 +23,22 @@ function calcPasswordHash(password, salt, iterations = 100000, keyLength = 64, d
|
|
|
23
23
|
function generateSalt(length = 16) {
|
|
24
24
|
return crypto.randomBytes(length).toString('hex');
|
|
25
25
|
}
|
|
26
|
+
function parseTimeToSeconds(time) {
|
|
27
|
+
const unit = time.slice(-1);
|
|
28
|
+
const value = parseInt(time.slice(0, -1), 10);
|
|
29
|
+
switch (unit) {
|
|
30
|
+
case 's':
|
|
31
|
+
return value;
|
|
32
|
+
case 'm':
|
|
33
|
+
return value * 60;
|
|
34
|
+
case 'h':
|
|
35
|
+
return value * 60 * 60;
|
|
36
|
+
case 'd':
|
|
37
|
+
return value * 60 * 60 * 24;
|
|
38
|
+
default:
|
|
39
|
+
throw new Error(`Invalid time unit: ${unit}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
26
42
|
class AdminForthAuth {
|
|
27
43
|
constructor(adminforth) {
|
|
28
44
|
this.adminforth = adminforth;
|
|
@@ -32,11 +48,14 @@ class AdminForthAuth {
|
|
|
32
48
|
}
|
|
33
49
|
setAuthCookie({ expireInDays, response, username, pk }) {
|
|
34
50
|
const expiresIn = expireInDays ? `${expireInDays}d` : (process.env.ADMINFORTH_AUTH_EXPIRESIN || '24h');
|
|
51
|
+
// might be h,m,d in string
|
|
52
|
+
const expiresInSec = parseTimeToSeconds(expiresIn);
|
|
35
53
|
const token = this.issueJWT({ username, pk }, 'auth', expiresIn);
|
|
36
|
-
|
|
54
|
+
const expiresCookieFormat = new Date(Date.now() + expiresInSec * 1000).toUTCString();
|
|
55
|
+
response.setHeader('Set-Cookie', `adminforth_jwt=${token}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=${expiresCookieFormat}`);
|
|
37
56
|
}
|
|
38
57
|
removeCustomCookie({ response, name }) {
|
|
39
|
-
response.setHeader('Set-Cookie', `
|
|
58
|
+
response.setHeader('Set-Cookie', `adminforth_${name}=; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=Thu, 01 Jan 1970 00:00:00 GMT`);
|
|
40
59
|
}
|
|
41
60
|
setCustomCookie({ response, payload }) {
|
|
42
61
|
const { name, value, expiry, httpOnly } = payload;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
<div
|
|
4
|
+
<div class="flex items-center w-full p-4 text-gray-500 rounded-lg shadow-lg dark:text-gray-400 dark:bg-gray-800 bg-white"
|
|
5
5
|
role="alert"
|
|
6
6
|
:class="
|
|
7
7
|
{
|
|
@@ -156,6 +156,13 @@ async function saveRecord() {
|
|
|
156
156
|
});
|
|
157
157
|
if (resp.error) {
|
|
158
158
|
showErrorTost(resp.error);
|
|
159
|
+
} else {
|
|
160
|
+
window.adminforth.alert({
|
|
161
|
+
message: 'Record updated successfully',
|
|
162
|
+
variant: 'success',
|
|
163
|
+
timeout: 400000
|
|
164
|
+
|
|
165
|
+
});
|
|
159
166
|
}
|
|
160
167
|
saving.value = false;
|
|
161
168
|
router.push({ name: 'resource-show', params: { resourceId: route.params.resourceId, primaryKey: coreStore.record[coreStore.primaryKey] } });
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
<td class="px-6 py-4 whitespace-nowrap "> <!--align-top-->
|
|
79
79
|
{{ column.label }}
|
|
80
80
|
</td>
|
|
81
|
-
<td class="px-6 py-4 whitespace-nowrap whitespace-pre-wrap">
|
|
81
|
+
<td class="px-6 py-4 whitespace-nowrap whitespace-pre-wrap" :data-af-column="column.name">
|
|
82
82
|
<component
|
|
83
83
|
v-if="column?.components?.show"
|
|
84
84
|
:is="getCustomComponent(column?.components?.show)"
|