Skip to content

Commit 5571213

Browse files
committed
Merge branch 'main' of github.com:devforth/adminforth into next
AdminForth/1715/translations-doesnt-work-on-li AdminForth/1715/translations-doesnt-work-on-li
2 parents 47c05c5 + 445b239 commit 5571213

16 files changed

Lines changed: 253 additions & 183 deletions

File tree

adminforth/documentation/docs/tutorial/001-gettingStarted.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ nvm alias default 20
1919
nvm use 20
2020
```
2121

22+
2223
## Creating an AdminForth Project
2324

2425
The recommended way to get started with AdminForth is via the **`create-app`** CLI, which scaffolds a basic fully functional back-office application. Apart boilerplate it creates one resource for users management.

adminforth/documentation/docs/tutorial/09-Plugins/02-TwoFactorsAuth.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ If you wan't to call 2FA verification modal from the backend for verification, y
237237
t2fa.verifyAuto(adminUser);
238238
```
239239
This method opens 2FA verification modal at the frontend and then returns verification result.
240+
The modal is shown only in the same browser tab/window which made the backend request.
241+
Because of this, `verifyAuto` must be called from a browser-initiated request handled by AdminForth request context, for example from an endpoint wrapped with `admin.express.authorize`.
240242
241243
Here is an example:
242244
@@ -932,4 +934,3 @@ After adding passkey you can use passkey, instead of TOTP:
932934
933935
934936
935-

adminforth/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export * from './types/Back.js';
4848
export * from './types/Common.js';
4949
export * from './types/adapters/index.js';
5050
export * from './modules/filtersTools.js';
51+
export * from './modules/requestContext.js';
5152
export { interpretResource };
5253
export { AdminForthPlugin };
5354
export { suggestIfTypo, RateLimiter, RAMLock, getClientIp, convertPeriodToSeconds };
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { AsyncLocalStorage } from 'async_hooks';
2+
3+
export const ADMINFORTH_CLIENT_ID_HEADER = 'x-adminforth-client-id';
4+
5+
export type AdminForthRequestContext = {
6+
websocketClientId?: string;
7+
};
8+
9+
const requestContextStorage = new AsyncLocalStorage<AdminForthRequestContext>();
10+
11+
export function runWithRequestContext<T>(context: AdminForthRequestContext, callback: () => T): T {
12+
return requestContextStorage.run(context, callback);
13+
}
14+
15+
export function getRequestContext(): AdminForthRequestContext | undefined {
16+
return requestContextStorage.getStore();
17+
}
18+
19+
export function getRequestWebsocketClientId(): string | undefined {
20+
return requestContextStorage.getStore()?.websocketClientId;
21+
}

adminforth/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@
129129
"typescript": "^5.4.5"
130130
},
131131
"peerDependencies": {
132-
"@adminforth/connector-clickhouse": "^1.0.1",
133-
"@adminforth/connector-mongo": "^1.0.0",
134-
"@adminforth/connector-mysql": "^1.0.0",
135-
"@adminforth/connector-postgres": "^1.0.0",
136-
"@adminforth/connector-sqlite": "^1.0.0"
132+
"@adminforth/connector-clickhouse": "^1.0.2",
133+
"@adminforth/connector-mongo": "^1.0.1",
134+
"@adminforth/connector-mysql": "^1.0.1",
135+
"@adminforth/connector-postgres": "^1.0.1",
136+
"@adminforth/connector-sqlite": "^1.0.1"
137137
},
138138
"peerDependenciesMeta": {
139139
"@adminforth/connector-sqlite": {

adminforth/pnpm-lock.yaml

Lines changed: 110 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/pnpm-workspace.yaml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ packages:
33

44
allowBuilds:
55
'@parcel/watcher': true
6+
adminforth: true
67
better-sqlite3: true
78
esbuild: true
89
vue-demi: true
910

1011
minimumReleaseAgeExclude:
11-
- '@adminforth/connector-sqlite@1.0.0'
12-
- adminforth@2.72.3
13-
- '@adminforth/connector-clickhouse@1.0.1'
14-
- '@adminforth/connector-mongo@1.0.0'
15-
- '@adminforth/connector-mysql@1.0.0'
16-
- '@adminforth/connector-postgres@1.0.0'
17-
18-
overrides:
19-
adminforth: 'link:'
12+
- '@adminforth/connector-clickhouse@1.0.2'
13+
- '@adminforth/connector-mongo@1.0.1'
14+
- '@adminforth/connector-mysql@1.0.1'
15+
- '@adminforth/connector-postgres@1.0.1'
16+
- '@adminforth/connector-sqlite@1.0.1'
17+
- adminforth@3.0.2

adminforth/servers/common.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AdminUser } from "../types/Common.js";
55

66
export class WebSocketClient implements IWebSocketClient {
77
id: string;
8+
clientId?: string;
89
lastPing: number;
910
topics: Set<string>;
1011
adminUser: AdminUser;
@@ -14,8 +15,9 @@ export class WebSocketClient implements IWebSocketClient {
1415
onMessage: (handler: (message: string) => void) => void;
1516
onClose: (handler: () => void) => void;
1617

17-
constructor({ id, send, close, onMessage, onClose, adminUser }) {
18+
constructor({ id, clientId, send, close, onMessage, onClose, adminUser }) {
1819
this.id = id;
20+
this.clientId = clientId;
1921
this.send = send;
2022
this.close = close;
2123
this.onMessage = onMessage;
@@ -25,4 +27,4 @@ export class WebSocketClient implements IWebSocketClient {
2527
this.topics = new Set();
2628
this.adminUser = adminUser;
2729
}
28-
}
30+
}

0 commit comments

Comments
 (0)