@nest-boot/auth 7.9.4 → 7.10.0
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/dist/auth.guard.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CanActivate, ExecutionContext } from "@nestjs/common";
|
|
1
|
+
import { type CanActivate, type ExecutionContext } from "@nestjs/common";
|
|
2
2
|
import { Reflector } from "@nestjs/core";
|
|
3
3
|
/**
|
|
4
4
|
* Guard that enforces authentication on routes.
|
|
@@ -13,10 +13,16 @@ export declare class AuthGuard implements CanActivate {
|
|
|
13
13
|
* @param reflector - NestJS reflector for reading route metadata
|
|
14
14
|
*/
|
|
15
15
|
constructor(reflector: Reflector);
|
|
16
|
+
/**
|
|
17
|
+
* Determines whether the current route is marked as public.
|
|
18
|
+
* @param context - The execution context of the current request
|
|
19
|
+
* @returns True when authentication should be skipped
|
|
20
|
+
*/
|
|
21
|
+
protected isPublic(context: ExecutionContext): boolean;
|
|
16
22
|
/**
|
|
17
23
|
* Determines whether the current request is allowed to proceed.
|
|
18
24
|
* @param context - The execution context of the current request
|
|
19
|
-
* @returns
|
|
25
|
+
* @returns A NestJS guard activation result
|
|
20
26
|
*/
|
|
21
|
-
canActivate(context: ExecutionContext):
|
|
27
|
+
canActivate(context: ExecutionContext): ReturnType<CanActivate["canActivate"]>;
|
|
22
28
|
}
|
package/dist/auth.guard.js
CHANGED
|
@@ -30,15 +30,23 @@ let AuthGuard = class AuthGuard {
|
|
|
30
30
|
this.reflector = reflector;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* Determines whether the current
|
|
33
|
+
* Determines whether the current route is marked as public.
|
|
34
34
|
* @param context - The execution context of the current request
|
|
35
|
-
* @returns
|
|
35
|
+
* @returns True when authentication should be skipped
|
|
36
36
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
isPublic(context) {
|
|
38
|
+
return !!this.reflector.getAllAndOverride(auth_constants_1.IS_PUBLIC_KEY, [
|
|
39
39
|
context.getHandler(),
|
|
40
40
|
context.getClass(),
|
|
41
|
-
])
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Determines whether the current request is allowed to proceed.
|
|
45
|
+
* @param context - The execution context of the current request
|
|
46
|
+
* @returns A NestJS guard activation result
|
|
47
|
+
*/
|
|
48
|
+
canActivate(context) {
|
|
49
|
+
if (this.isPublic(context)) {
|
|
42
50
|
return true;
|
|
43
51
|
}
|
|
44
52
|
return !!request_context_1.RequestContext.get(session_entity_1.BaseSession);
|
package/dist/auth.guard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.guard.js","sourceRoot":"","sources":["../src/auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gEAA4D;AAC5D,
|
|
1
|
+
{"version":3,"file":"auth.guard.js","sourceRoot":"","sources":["../src/auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gEAA4D;AAC5D,2CAIwB;AACxB,uCAAyC;AAEzC,qDAAiD;AACjD,8DAAwD;AAExD;;;;;;GAMG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAS;IACpB;;OAEG;IACH,YAA+B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAEvD;;;;OAIG;IACO,QAAQ,CAAC,OAAyB;QAC1C,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,8BAAa,EAAE;YACvD,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACnB,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,WAAW,CACT,OAAyB;QAEzB,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,CAAC,CAAC,gCAAc,CAAC,GAAG,CAAC,4BAAW,CAAC,CAAC;IAC3C,CAAC;CACF,CAAA;AAhCY,8BAAS;oBAAT,SAAS;IADrB,IAAA,mBAAU,GAAE;qCAK+B,gBAAS;GAJxC,SAAS,CAgCrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const rxjs_1 = require("rxjs");
|
|
4
|
+
const auth_constants_1 = require("./auth.constants");
|
|
5
|
+
const auth_guard_1 = require("./auth.guard");
|
|
6
|
+
class PromiseAuthGuard extends auth_guard_1.AuthGuard {
|
|
7
|
+
canActivate(_context) {
|
|
8
|
+
return Promise.resolve(true);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class ObservableAuthGuard extends auth_guard_1.AuthGuard {
|
|
12
|
+
canActivate(_context) {
|
|
13
|
+
return (0, rxjs_1.of)(true);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
class PublicAwareAuthGuard extends auth_guard_1.AuthGuard {
|
|
17
|
+
isContextPublic(context) {
|
|
18
|
+
return this.isPublic(context);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
describe("AuthGuard", () => {
|
|
22
|
+
it("allows subclasses to return the full CanActivate result type", () => {
|
|
23
|
+
expect(PromiseAuthGuard).toBeDefined();
|
|
24
|
+
expect(ObservableAuthGuard).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
it("allows subclasses to reuse the public route metadata lookup", () => {
|
|
27
|
+
const handler = () => undefined;
|
|
28
|
+
class TestController {
|
|
29
|
+
}
|
|
30
|
+
const context = {
|
|
31
|
+
getClass: jest.fn(() => TestController),
|
|
32
|
+
getHandler: jest.fn(() => handler),
|
|
33
|
+
};
|
|
34
|
+
const getAllAndOverride = jest.fn(() => true);
|
|
35
|
+
const guard = new PublicAwareAuthGuard({
|
|
36
|
+
getAllAndOverride,
|
|
37
|
+
});
|
|
38
|
+
expect(guard.isContextPublic(context)).toBe(true);
|
|
39
|
+
expect(getAllAndOverride).toHaveBeenCalledWith(auth_constants_1.IS_PUBLIC_KEY, [
|
|
40
|
+
handler,
|
|
41
|
+
TestController,
|
|
42
|
+
]);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=auth.guard.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.guard.spec.js","sourceRoot":"","sources":["../src/auth.guard.spec.ts"],"names":[],"mappings":";;AAEA,+BAA0B;AAE1B,qDAAiD;AACjD,6CAAyC;AAEzC,MAAM,gBAAiB,SAAQ,sBAAS;IAC7B,WAAW,CAClB,QAA0B;QAE1B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,mBAAoB,SAAQ,sBAAS;IAChC,WAAW,CAClB,QAA0B;QAE1B,OAAO,IAAA,SAAE,EAAC,IAAI,CAAC,CAAC;IAClB,CAAC;CACF;AAED,MAAM,oBAAqB,SAAQ,sBAAS;IAC1C,eAAe,CAAC,OAAyB;QACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;CACF;AAED,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;QACtE,MAAM,CAAC,gBAAgB,CAAC,CAAC,WAAW,EAAE,CAAC;QACvC,MAAM,CAAC,mBAAmB,CAAC,CAAC,WAAW,EAAE,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC;QAChC,MAAM,cAAc;SAAG;QAEvB,MAAM,OAAO,GAAG;YACd,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC;YACvC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC;SACJ,CAAC;QAEjC,MAAM,iBAAiB,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QAC9C,MAAM,KAAK,GAAG,IAAI,oBAAoB,CAAC;YACrC,iBAAiB;SACM,CAAC,CAAC;QAE3B,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,CAAC,iBAAiB,CAAC,CAAC,oBAAoB,CAAC,8BAAa,EAAE;YAC5D,OAAO;YACP,cAAc;SACf,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|