Skip to content

Commit 628eef8

Browse files
committed
Revert "feat: add "adminUserAuthorize" hook"
This reverts commit 946c790.
1 parent 899a45d commit 628eef8

File tree

2 files changed

+2
-46
lines changed

2 files changed

+2
-46
lines changed

adminforth/servers/express.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import path from 'path';
33
import fs from 'fs';
44
import { Express } from 'express';
55
import fetch from 'node-fetch';
6-
import { AdminUserAuthorizeFunction, IAdminForth, IExpressHttpServer, HttpExtra } from '../types/Back.js';
6+
import { IAdminForth, IExpressHttpServer } from '../types/Back.js';
77
import { WebSocketServer } from 'ws';
88
import { WebSocketClient } from './common.js';
99
import { AdminUser } from '../types/Common.js';
1010
import http from 'http';
1111
import { randomUUID } from 'crypto';
12-
import { listify } from '../modules/utils.js';
1312

1413
function replaceAtStart(string, substring) {
1514
if (string.startsWith(substring)) {
@@ -217,25 +216,6 @@ class ExpressServer implements IExpressHttpServer {
217216
this.server.listen(...args);
218217
}
219218

220-
async processAuthorizeCallbacks(adminUser: AdminUser, toReturn: { error?: string, allowed: boolean }, response: Response, extra: any) {
221-
const adminUserAuthorize = this.adminforth.config.auth.adminUserAuthorize as (AdminUserAuthorizeFunction[] | undefined);
222-
223-
for (const hook of listify(adminUserAuthorize)) {
224-
const resp = await hook({
225-
adminUser,
226-
response,
227-
adminforth: this.adminforth,
228-
extra,
229-
});
230-
if (resp?.allowed === false || resp?.error) {
231-
// delete all items from toReturn and add these:
232-
toReturn.allowed = resp?.allowed;
233-
toReturn.error = resp?.error;
234-
break;
235-
}
236-
}
237-
}
238-
239219

240220
authorize(handler) {
241221
return async (req, res, next) => {
@@ -268,13 +248,7 @@ class ExpressServer implements IExpressHttpServer {
268248
res.status(401).send('Unauthorized by AdminForth');
269249
} else {
270250
req.adminUser = adminforthUser;
271-
const toReturn: { error?: string, allowed: boolean } = { allowed: true };
272-
await this.processAuthorizeCallbacks(adminforthUser, toReturn, res, {});
273-
if (!toReturn.allowed) {
274-
res.status(401).send('Unauthorized by AdminForth');
275-
} else {
276-
handler(req, res, next);
277-
}
251+
handler(req, res, next);
278252
}
279253
};
280254
}

adminforth/types/Back.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -611,19 +611,6 @@ export type BeforeLoginConfirmationFunction = (params?: {
611611
}
612612
}>;
613613

614-
/**
615-
* Allow to make extra authorization
616-
*/
617-
export type AdminUserAuthorizeFunction = ((params?: {
618-
adminUser: AdminUser,
619-
response: IAdminForthHttpResponse,
620-
adminforth: IAdminForth,
621-
extra?: HttpExtra,
622-
}) => Promise<{
623-
error?: string,
624-
allowed?: boolean,
625-
}>);
626-
627614

628615
/**
629616
* Data source describes database connection which will be used to fetch data for resources.
@@ -1022,11 +1009,6 @@ export interface AdminForthInputConfig {
10221009
*/
10231010
beforeLoginConfirmation?: BeforeLoginConfirmationFunction | Array<BeforeLoginConfirmationFunction>,
10241011

1025-
/**
1026-
* Array of functions which will be called before any request to AdminForth API.
1027-
*/
1028-
adminUserAuthorize?: AdminUserAuthorizeFunction | Array<AdminUserAuthorizeFunction>,
1029-
10301012
/**
10311013
* Optionally if your users table has a field(column) with full name, you can set it here.
10321014
* This field will be used to display user name in the top right corner of the admin panel.

0 commit comments

Comments
 (0)