@aenode/nest-auth 0.0.36 → 0.0.37
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/lib/guards/auth.guard.js +14 -6
- package/dist/lib/guards/auth.guard.js.map +1 -1
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/guards/auth.guard.d.ts +0 -12
- package/dist/lib/guards/auth.guard.d.ts.map +0 -1
- package/dist/lib/index.d.ts +0 -4
- package/dist/lib/index.d.ts.map +0 -1
- package/dist/lib/metadata/index.d.ts +0 -2
- package/dist/lib/metadata/index.d.ts.map +0 -1
- package/dist/lib/metadata/index.js +0 -4
- package/dist/lib/metadata/index.js.map +0 -1
- package/dist/lib/metadata/public.d.ts +0 -18
- package/dist/lib/metadata/public.d.ts.map +0 -1
- package/dist/lib/metadata/public.js +0 -21
- package/dist/lib/metadata/public.js.map +0 -1
- package/dist/lib/nest-auth.d.ts +0 -2
- package/dist/lib/nest-auth.d.ts.map +0 -1
- package/dist/lib/utils/extract-bearer-token.d.ts +0 -10
- package/dist/lib/utils/extract-bearer-token.d.ts.map +0 -1
- package/dist/lib/utils/index.d.ts +0 -2
- package/dist/lib/utils/index.d.ts.map +0 -1
- package/dist/main.d.ts +0 -3
- package/dist/main.d.ts.map +0 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
|
|
2
|
+
import { _ as _ts_metadata } from "@swc/helpers/_/_ts_metadata";
|
|
3
|
+
import { isPublic } from '@aenode/nest-decorators';
|
|
4
|
+
import { Injectable, Scope, UnauthorizedException } from '@aenode/nest/common';
|
|
3
5
|
import { extractBearerToken } from '../utils/index.js';
|
|
4
|
-
|
|
5
|
-
* Check the target resource is public or check the user is authenciated and save the user information to the `request.user`.
|
|
6
|
-
*
|
|
7
|
-
*/ export class AuthGuard {
|
|
6
|
+
export class AuthGuard {
|
|
8
7
|
constructor(reflector){
|
|
9
8
|
this.reflector = reflector;
|
|
10
9
|
}
|
|
@@ -21,5 +20,14 @@ import { extractBearerToken } from '../utils/index.js';
|
|
|
21
20
|
return true;
|
|
22
21
|
}
|
|
23
22
|
}
|
|
23
|
+
AuthGuard = _ts_decorate([
|
|
24
|
+
Injectable({
|
|
25
|
+
scope: Scope.REQUEST
|
|
26
|
+
}),
|
|
27
|
+
_ts_metadata("design:type", Function),
|
|
28
|
+
_ts_metadata("design:paramtypes", [
|
|
29
|
+
typeof Reflector === "undefined" ? Object : Reflector
|
|
30
|
+
])
|
|
31
|
+
], AuthGuard);
|
|
24
32
|
|
|
25
33
|
//# sourceMappingURL=auth.guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/guards/auth.guard.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/guards/auth.guard.ts"],"sourcesContent":["import { isPublic } from '@aenode/nest-decorators';\nimport {\n Injectable,\n Scope,\n UnauthorizedException,\n type CanActivate,\n type ExecutionContext,\n} from '@aenode/nest/common';\nimport type { Reflector } from '@aenode/nest/core';\nimport { type Request } from '@aenode/nest/express';\nimport { type ExtendedRequest } from '@aenode/types';\nimport { extractBearerToken } from '../utils/index.js';\n\n/**\n * Check the target resource is public or check the user is authenciated and save the user information to the `request.user`.\n *\n */\n@Injectable({ scope: Scope.REQUEST })\nexport class AuthGuard implements CanActivate {\n constructor(protected readonly reflector: Reflector) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const req = context.switchToHttp().getRequest<ExtendedRequest & Request>();\n\n const isPublicResource = isPublic(context, this.reflector);\n\n if (isPublicResource) {\n return true;\n }\n\n const token = extractBearerToken(req);\n\n if (!token) {\n throw new UnauthorizedException('Authentication token is not provided');\n }\n\n return true;\n }\n}\n"],"names":["isPublic","Injectable","Scope","UnauthorizedException","extractBearerToken","AuthGuard","reflector","canActivate","context","req","switchToHttp","getRequest","isPublicResource","token","scope","REQUEST"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,0BAA0B;AACnD,SACEC,UAAU,EACVC,KAAK,EACLC,qBAAqB,QAGhB,sBAAsB;AAI7B,SAASC,kBAAkB,QAAQ,oBAAoB;AAOvD,OAAO,MAAMC;IACX,YAAY,AAAmBC,SAAoB,CAAE;aAAtBA,YAAAA;IAAuB;IAEtD,MAAMC,YAAYC,OAAyB,EAAoB;QAC7D,MAAMC,MAAMD,QAAQE,YAAY,GAAGC,UAAU;QAE7C,MAAMC,mBAAmBZ,SAASQ,SAAS,IAAI,CAACF,SAAS;QAEzD,IAAIM,kBAAkB;YACpB,OAAO;QACT;QAEA,MAAMC,QAAQT,mBAAmBK;QAEjC,IAAI,CAACI,OAAO;YACV,MAAM,IAAIV,sBAAsB;QAClC;QAEA,OAAO;IACT;AACF;;;QArBcW,OAAOZ,MAAMa,OAAO"}
|
package/dist/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @index(['./**/*.ts', '!./**/*.spec.ts','!./**/index.ts', '!./**/_*.ts','!./**/{main,bootstrap}.ts', '!./**/generated/**'], f => `export * from '${f.path}.js'`)
|
|
2
2
|
export * from './guards/auth.guard.js';
|
|
3
|
+
export * from './meta/public.js';
|
|
3
4
|
export * from './nest-auth.js';
|
|
4
5
|
export * from './utils/extract-bearer-token.js';
|
|
5
6
|
|
package/dist/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/index.ts"],"sourcesContent":["// @index(['./**/*.ts', '!./**/*.spec.ts','!./**/index.ts', '!./**/_*.ts','!./**/{main,bootstrap}.ts', '!./**/generated/**'], f => `export * from '${f.path}.js'`)\nexport * from './guards/auth.guard.js';\nexport * from './nest-auth.js';\nexport * from './utils/extract-bearer-token.js';\n"],"names":[],"mappings":"AAAA,kKAAkK;AAClK,cAAc,yBAAyB;AACvC,cAAc,iBAAiB;AAC/B,cAAc,kCAAkC"}
|
|
1
|
+
{"version":3,"sources":["../../src/lib/index.ts"],"sourcesContent":["// @index(['./**/*.ts', '!./**/*.spec.ts','!./**/index.ts', '!./**/_*.ts','!./**/{main,bootstrap}.ts', '!./**/generated/**'], f => `export * from '${f.path}.js'`)\nexport * from './guards/auth.guard.js';\nexport * from './meta/public.js';\nexport * from './nest-auth.js';\nexport * from './utils/extract-bearer-token.js';\n"],"names":[],"mappings":"AAAA,kKAAkK;AAClK,cAAc,yBAAyB;AACvC,cAAc,mBAAmB;AACjC,cAAc,iBAAiB;AAC/B,cAAc,kCAAkC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aenode/nest-auth",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"description": "Nest auth module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ahmet Emrebas",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@aenode/constants": "workspace:*",
|
|
61
60
|
"@aenode/nest": "workspace:*",
|
|
62
|
-
"@
|
|
63
|
-
"@aenode/types": "workspace:*"
|
|
61
|
+
"@aenode/nest-decorators": "workspace:*",
|
|
62
|
+
"@aenode/types": "workspace:*",
|
|
63
|
+
"@swc/helpers": "~0.5.18"
|
|
64
64
|
}
|
|
65
65
|
}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type CanActivate, type ExecutionContext } from '@aenode/nest/common';
|
|
2
|
-
import { Reflector } from '@aenode/nest/core';
|
|
3
|
-
/**
|
|
4
|
-
* Check the target resource is public or check the user is authenciated and save the user information to the `request.user`.
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
export declare class AuthGuard implements CanActivate {
|
|
8
|
-
protected readonly reflector: Reflector;
|
|
9
|
-
constructor(reflector: Reflector);
|
|
10
|
-
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=auth.guard.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.guard.d.ts","sourceRoot":"","sources":["../../../src/lib/guards/auth.guard.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAM9C;;;GAGG;AACH,qBAAa,SAAU,YAAW,WAAW;IAC/B,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS;gBAApB,SAAS,EAAE,SAAS;IAC7C,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAiB/D"}
|
package/dist/lib/index.d.ts
DELETED
package/dist/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iCAAiC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/metadata/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/metadata/index.ts"],"sourcesContent":["// @index(['./**/*.ts', '!./**/*.spec.ts','!./**/index.ts', '!./**/_*.ts','!./**/main.ts', '!./**/generated/**'], f => `export * from '${f.path}.js'`)\nexport * from './public.js';\n"],"names":[],"mappings":"AAAA,sJAAsJ;AACtJ,cAAc,cAAc"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { MetadataToken } from '@aenode/constants';
|
|
2
|
-
import { type ExecutionContext } from '@aenode/nest/common';
|
|
3
|
-
import type { Reflector } from '@aenode/nest/core';
|
|
4
|
-
/**
|
|
5
|
-
* Mark the target resource as public which will bypass the authentication
|
|
6
|
-
*
|
|
7
|
-
* @returns Class/Method decorator
|
|
8
|
-
*/
|
|
9
|
-
export declare const Public: () => import("@aenode/nest/common").CustomDecorator<MetadataToken>;
|
|
10
|
-
/**
|
|
11
|
-
* Check the resource is marked as public or not.
|
|
12
|
-
*
|
|
13
|
-
* @param context nestjs execution context
|
|
14
|
-
* @param reflector nestjs core Reflector
|
|
15
|
-
* @returns boolean
|
|
16
|
-
*/
|
|
17
|
-
export declare function isPublic(context: ExecutionContext, reflector: Reflector): boolean;
|
|
18
|
-
//# sourceMappingURL=public.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/lib/metadata/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;;GAIG;AACH,eAAO,MAAM,MAAM,oEAAgD,CAAC;AAEpE;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAE,SAAS,GACnB,OAAO,CAKT"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { MetadataToken } from '@aenode/constants';
|
|
2
|
-
import { SetMetadata } from '@aenode/nest/common';
|
|
3
|
-
/**
|
|
4
|
-
* Mark the target resource as public which will bypass the authentication
|
|
5
|
-
*
|
|
6
|
-
* @returns Class/Method decorator
|
|
7
|
-
*/ export const Public = ()=>SetMetadata(MetadataToken.PUBLIC, true);
|
|
8
|
-
/**
|
|
9
|
-
* Check the resource is marked as public or not.
|
|
10
|
-
*
|
|
11
|
-
* @param context nestjs execution context
|
|
12
|
-
* @param reflector nestjs core Reflector
|
|
13
|
-
* @returns boolean
|
|
14
|
-
*/ export function isPublic(context, reflector) {
|
|
15
|
-
return !!reflector.getAllAndOverride(MetadataToken.PUBLIC, [
|
|
16
|
-
context.getHandler(),
|
|
17
|
-
context.getClass()
|
|
18
|
-
]);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=public.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/metadata/public.ts"],"sourcesContent":["import { MetadataToken } from '@aenode/constants';\nimport { SetMetadata, type ExecutionContext } from '@aenode/nest/common';\nimport type { Reflector } from '@aenode/nest/core';\n\n/**\n * Mark the target resource as public which will bypass the authentication\n *\n * @returns Class/Method decorator\n */\nexport const Public = () => SetMetadata(MetadataToken.PUBLIC, true);\n\n/**\n * Check the resource is marked as public or not.\n *\n * @param context nestjs execution context\n * @param reflector nestjs core Reflector\n * @returns boolean\n */\nexport function isPublic(\n context: ExecutionContext,\n reflector: Reflector,\n): boolean {\n return !!reflector.getAllAndOverride<boolean | undefined>(\n MetadataToken.PUBLIC,\n [context.getHandler(), context.getClass()],\n );\n}\n"],"names":["MetadataToken","SetMetadata","Public","PUBLIC","isPublic","context","reflector","getAllAndOverride","getHandler","getClass"],"mappings":"AAAA,SAASA,aAAa,QAAQ,oBAAoB;AAClD,SAASC,WAAW,QAA+B,sBAAsB;AAGzE;;;;CAIC,GACD,OAAO,MAAMC,SAAS,IAAMD,YAAYD,cAAcG,MAAM,EAAE,MAAM;AAEpE;;;;;;CAMC,GACD,OAAO,SAASC,SACdC,OAAyB,EACzBC,SAAoB;IAEpB,OAAO,CAAC,CAACA,UAAUC,iBAAiB,CAClCP,cAAcG,MAAM,EACpB;QAACE,QAAQG,UAAU;QAAIH,QAAQI,QAAQ;KAAG;AAE9C"}
|
package/dist/lib/nest-auth.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nest-auth.d.ts","sourceRoot":"","sources":["../../src/lib/nest-auth.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,WAEvB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Request } from '@aenode/nest/express';
|
|
2
|
-
import type { ExtendedRequest } from '@aenode/types';
|
|
3
|
-
/**
|
|
4
|
-
* Extract the bearer token from the authorization header, validate, and return.
|
|
5
|
-
*
|
|
6
|
-
* @param request Express request
|
|
7
|
-
* @returns authentication token
|
|
8
|
-
*/
|
|
9
|
-
export declare function extractBearerToken(request: ExtendedRequest & Request): string;
|
|
10
|
-
//# sourceMappingURL=extract-bearer-token.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extract-bearer-token.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/extract-bearer-token.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,UAcpE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,2BAA2B,CAAC"}
|
package/dist/main.d.ts
DELETED
package/dist/main.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
|