@naturalcycles/backend-lib 9.46.1 → 9.46.2
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.
|
@@ -20,8 +20,8 @@ export interface AdminInfo {
|
|
|
20
20
|
* Base implementation based on Firebase Auth tokens passed as 'admin_token' cookie.
|
|
21
21
|
*/
|
|
22
22
|
export declare class BaseAdminService {
|
|
23
|
-
private
|
|
24
|
-
constructor(
|
|
23
|
+
private loadFirebaseAuth;
|
|
24
|
+
constructor(loadFirebaseAuth: () => Promise<FirebaseAdmin.auth.Auth>, cfg: AdminServiceCfg);
|
|
25
25
|
cfg: Required<AdminServiceCfg>;
|
|
26
26
|
adminInfoDisabled(): AdminInfo;
|
|
27
27
|
/**
|
|
@@ -37,6 +37,7 @@ export declare class BaseAdminService {
|
|
|
37
37
|
*/
|
|
38
38
|
protected onPermissionCheck(req: BackendRequest, email: string, reqPermissions: string[], required: boolean, granted: boolean, meta?: Record<string, any>): Promise<void>;
|
|
39
39
|
getEmailByToken(req: BackendRequest, adminToken?: string): Promise<string | undefined>;
|
|
40
|
+
private getFirebaseAuth;
|
|
40
41
|
/**
|
|
41
42
|
* Current implementation is based on req=Request (from Express).
|
|
42
43
|
* Override if needed.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { _Memo } from '@naturalcycles/js-lib/decorators';
|
|
1
3
|
import { _assert, AppError } from '@naturalcycles/js-lib/error';
|
|
2
4
|
import { dimGrey, green, red } from '@naturalcycles/nodejs-lib/colors';
|
|
3
5
|
const adminInfoDisabled = () => ({
|
|
@@ -8,9 +10,9 @@ const adminInfoDisabled = () => ({
|
|
|
8
10
|
* Base implementation based on Firebase Auth tokens passed as 'admin_token' cookie.
|
|
9
11
|
*/
|
|
10
12
|
export class BaseAdminService {
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
13
|
-
this.
|
|
13
|
+
loadFirebaseAuth;
|
|
14
|
+
constructor(loadFirebaseAuth, cfg) {
|
|
15
|
+
this.loadFirebaseAuth = loadFirebaseAuth;
|
|
14
16
|
this.cfg = {
|
|
15
17
|
adminTokenKey: 'admin_token',
|
|
16
18
|
authEnabled: true,
|
|
@@ -47,7 +49,8 @@ export class BaseAdminService {
|
|
|
47
49
|
if (!adminToken)
|
|
48
50
|
return;
|
|
49
51
|
try {
|
|
50
|
-
const
|
|
52
|
+
const auth = await this.getFirebaseAuth();
|
|
53
|
+
const decodedToken = await auth.verifyIdToken(adminToken);
|
|
51
54
|
const email = decodedToken?.email;
|
|
52
55
|
req.log(`admin email: ${dimGrey(email)}`);
|
|
53
56
|
return email;
|
|
@@ -63,6 +66,9 @@ export class BaseAdminService {
|
|
|
63
66
|
req.error(`getEmailByToken error:`, err);
|
|
64
67
|
}
|
|
65
68
|
}
|
|
69
|
+
async getFirebaseAuth() {
|
|
70
|
+
return await this.loadFirebaseAuth();
|
|
71
|
+
}
|
|
66
72
|
/**
|
|
67
73
|
* Current implementation is based on req=Request (from Express).
|
|
68
74
|
* Override if needed.
|
|
@@ -193,3 +199,6 @@ export class BaseAdminService {
|
|
|
193
199
|
};
|
|
194
200
|
}
|
|
195
201
|
}
|
|
202
|
+
__decorate([
|
|
203
|
+
_Memo()
|
|
204
|
+
], BaseAdminService.prototype, "getFirebaseAuth", null);
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _Memo } from '@naturalcycles/js-lib/decorators'
|
|
1
2
|
import { _assert, AppError } from '@naturalcycles/js-lib/error'
|
|
2
3
|
import { dimGrey, green, red } from '@naturalcycles/nodejs-lib/colors'
|
|
3
4
|
import type FirebaseAdmin from 'firebase-admin'
|
|
@@ -32,7 +33,7 @@ const adminInfoDisabled = (): AdminInfo => ({
|
|
|
32
33
|
*/
|
|
33
34
|
export class BaseAdminService {
|
|
34
35
|
constructor(
|
|
35
|
-
private
|
|
36
|
+
private loadFirebaseAuth: () => Promise<FirebaseAdmin.auth.Auth>,
|
|
36
37
|
cfg: AdminServiceCfg,
|
|
37
38
|
) {
|
|
38
39
|
this.cfg = {
|
|
@@ -91,7 +92,8 @@ export class BaseAdminService {
|
|
|
91
92
|
if (!adminToken) return
|
|
92
93
|
|
|
93
94
|
try {
|
|
94
|
-
const
|
|
95
|
+
const auth = await this.getFirebaseAuth()
|
|
96
|
+
const decodedToken = await auth.verifyIdToken(adminToken)
|
|
95
97
|
const email = decodedToken?.email
|
|
96
98
|
req.log(`admin email: ${dimGrey(email)}`)
|
|
97
99
|
return email
|
|
@@ -109,6 +111,11 @@ export class BaseAdminService {
|
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
|
|
114
|
+
@_Memo()
|
|
115
|
+
private async getFirebaseAuth(): Promise<FirebaseAdmin.auth.Auth> {
|
|
116
|
+
return await this.loadFirebaseAuth()
|
|
117
|
+
}
|
|
118
|
+
|
|
112
119
|
/**
|
|
113
120
|
* Current implementation is based on req=Request (from Express).
|
|
114
121
|
* Override if needed.
|