@nest-boot/auth 7.3.0 → 7.4.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-module-options.interface.d.ts +1 -0
- package/dist/auth.middleware.js +25 -20
- package/dist/auth.middleware.js.map +1 -1
- package/dist/auth.module-definition.d.ts +1 -3
- package/dist/auth.module-definition.js +1 -6
- package/dist/auth.module-definition.js.map +1 -1
- package/dist/auth.module.d.ts +5 -8
- package/dist/auth.module.js +35 -31
- package/dist/auth.module.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -4
- package/dist/auth.interceptor.d.ts +0 -17
- package/dist/auth.interceptor.js +0 -91
- package/dist/auth.interceptor.js.map +0 -1
|
@@ -2,6 +2,7 @@ import { RouteInfo, Type } from "@nestjs/common/interfaces";
|
|
|
2
2
|
import { BetterAuthOptions } from "better-auth";
|
|
3
3
|
import { MikroOrmAdapterConfig } from "./adapters/mikro-orm-adapter";
|
|
4
4
|
export interface AuthModuleMiddlewareOptions {
|
|
5
|
+
register?: boolean;
|
|
5
6
|
includeRoutes?: (string | RouteInfo | Type)[];
|
|
6
7
|
excludeRoutes?: (string | RouteInfo)[];
|
|
7
8
|
}
|
package/dist/auth.middleware.js
CHANGED
|
@@ -24,33 +24,38 @@ let AuthMiddleware = class AuthMiddleware {
|
|
|
24
24
|
this.em = em;
|
|
25
25
|
}
|
|
26
26
|
async getSession(req) {
|
|
27
|
-
const headers = new Headers();
|
|
28
|
-
Object.entries(req.headers).forEach(([key, value]) => {
|
|
29
|
-
if (value) {
|
|
30
|
-
if (Array.isArray(value)) {
|
|
31
|
-
value.forEach((v) => {
|
|
32
|
-
headers.append(key, v);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
headers.set(key, value);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
27
|
return await this.authService.auth.api.getSession({
|
|
41
|
-
headers,
|
|
28
|
+
headers: Object.entries(req.headers).reduce((headers, [key, value]) => {
|
|
29
|
+
if (value) {
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
for (const item of value) {
|
|
32
|
+
headers.append(key, item);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
headers.append(key, value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return headers;
|
|
40
|
+
}, new Headers()),
|
|
42
41
|
});
|
|
43
42
|
}
|
|
44
43
|
async use(req, res, next) {
|
|
45
44
|
const data = await this.getSession(req);
|
|
46
|
-
if (data) {
|
|
47
|
-
|
|
45
|
+
if (!data) {
|
|
46
|
+
next();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const [user, session] = await Promise.all([
|
|
50
|
+
this.em.findOne(this.options.entities.user, {
|
|
48
51
|
id: data.user.id,
|
|
49
|
-
})
|
|
50
|
-
|
|
52
|
+
}),
|
|
53
|
+
this.em.findOne(this.options.entities.session, {
|
|
51
54
|
token: data.session.token,
|
|
52
|
-
})
|
|
53
|
-
|
|
55
|
+
}),
|
|
56
|
+
]);
|
|
57
|
+
res.locals.user = user;
|
|
58
|
+
res.locals.session = session;
|
|
54
59
|
next();
|
|
55
60
|
}
|
|
56
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.middleware.js","sourceRoot":"","sources":["../src/auth.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAAgD;AAChD,2CAAoE;AAGpE,qEAAgE;AAChE,iDAA6C;AAItC,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YAEmB,OAA0B,EAC1B,WAAwB,EACxB,EAAiB;QAFjB,YAAO,GAAP,OAAO,CAAmB;QAC1B,gBAAW,GAAX,WAAW,CAAa;QACxB,OAAE,GAAF,EAAE,CAAe;IACjC,CAAC;IAC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AAE,CAAC;YACV,IAAI,EAAE,CAAC;YACP,OAAO;QACT,CAAC;QAED,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACxC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE;gBAC1C,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE;aACjB,CAAC;YACF,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE;gBAC7C,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;aAC1B,CAAC;SACH,CAAC,CAAC;QAEH,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;QACvB,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;QAE7B,IAAI,EAAE,CAAC;IACT,CAAC;CACF,CAAA;AA9CY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,6CAAoB,CAAC,CAAA;6CAEC,0BAAW;QACpB,oBAAa;GALzB,cAAc,CA8C1B"}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import { type AuthModuleOptions } from "./auth-module-options.interface";
|
|
2
|
-
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<AuthModuleOptions, "
|
|
3
|
-
isGlobal: boolean;
|
|
4
|
-
}>, MODULE_OPTIONS_TOKEN: string | symbol;
|
|
2
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<AuthModuleOptions, "forRoot", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol;
|
|
@@ -4,11 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = void 0;
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
_a = new common_1.ConfigurableModuleBuilder()
|
|
7
|
-
.
|
|
8
|
-
isGlobal: false,
|
|
9
|
-
}, (definition, extras) => ({
|
|
10
|
-
...definition,
|
|
11
|
-
global: extras.isGlobal,
|
|
12
|
-
}))
|
|
7
|
+
.setClassMethodName("forRoot")
|
|
13
8
|
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN;
|
|
14
9
|
//# sourceMappingURL=auth.module-definition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.module-definition.js","sourceRoot":"","sources":["../src/auth.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAI9C,KACX,IAAI,kCAAyB,EAAqB;KAC/C,
|
|
1
|
+
{"version":3,"file":"auth.module-definition.js","sourceRoot":"","sources":["../src/auth.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAI9C,KACX,IAAI,kCAAyB,EAAqB;KAC/C,kBAAkB,CAAC,SAAS,CAAC;KAC7B,KAAK,EAAE,EAHG,+BAAuB,+BAAE,4BAAoB,2BAG/C"}
|
package/dist/auth.module.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { MiddlewareConsumer, NestModule
|
|
2
|
-
import { HttpAdapterHost } from "@nestjs/core";
|
|
3
|
-
import { Auth } from "better-auth";
|
|
1
|
+
import { MiddlewareConsumer, NestModule } from "@nestjs/common";
|
|
4
2
|
import { ConfigurableModuleClass } from "./auth.module-definition";
|
|
3
|
+
import { AuthService } from "./auth.service";
|
|
5
4
|
import { AuthModuleOptions } from "./auth-module-options.interface";
|
|
6
|
-
export declare class AuthModule extends ConfigurableModuleClass implements NestModule
|
|
7
|
-
private readonly
|
|
8
|
-
private readonly auth;
|
|
5
|
+
export declare class AuthModule extends ConfigurableModuleClass implements NestModule {
|
|
6
|
+
private readonly authService;
|
|
9
7
|
private readonly options;
|
|
10
|
-
constructor(
|
|
8
|
+
constructor(authService: AuthService, options: AuthModuleOptions);
|
|
11
9
|
configure(consumer: MiddlewareConsumer): void;
|
|
12
|
-
onModuleInit(): void;
|
|
13
10
|
}
|
package/dist/auth.module.js
CHANGED
|
@@ -16,7 +16,6 @@ exports.AuthModule = void 0;
|
|
|
16
16
|
const core_1 = require("@mikro-orm/core");
|
|
17
17
|
const request_context_1 = require("@nest-boot/request-context");
|
|
18
18
|
const common_1 = require("@nestjs/common");
|
|
19
|
-
const core_2 = require("@nestjs/core");
|
|
20
19
|
const better_auth_1 = require("better-auth");
|
|
21
20
|
const node_1 = require("better-auth/node");
|
|
22
21
|
const mikro_orm_adapter_1 = require("./adapters/mikro-orm-adapter");
|
|
@@ -24,48 +23,53 @@ const auth_constants_1 = require("./auth.constants");
|
|
|
24
23
|
const auth_middleware_1 = require("./auth.middleware");
|
|
25
24
|
const auth_module_definition_1 = require("./auth.module-definition");
|
|
26
25
|
const auth_service_1 = require("./auth.service");
|
|
27
|
-
const authProvider = {
|
|
28
|
-
provide: auth_constants_1.AUTH_TOKEN,
|
|
29
|
-
inject: [auth_module_definition_1.MODULE_OPTIONS_TOKEN, core_1.MikroORM],
|
|
30
|
-
useFactory: (options, orm) => (0, better_auth_1.betterAuth)({
|
|
31
|
-
...options,
|
|
32
|
-
database: (0, mikro_orm_adapter_1.mikroOrmAdapter)({
|
|
33
|
-
orm,
|
|
34
|
-
entities: options.entities,
|
|
35
|
-
}),
|
|
36
|
-
}),
|
|
37
|
-
};
|
|
38
26
|
let AuthModule = class AuthModule extends auth_module_definition_1.ConfigurableModuleClass {
|
|
39
|
-
constructor(
|
|
27
|
+
constructor(authService, options) {
|
|
40
28
|
super();
|
|
41
|
-
this.
|
|
42
|
-
this.auth = auth;
|
|
29
|
+
this.authService = authService;
|
|
43
30
|
this.options = options;
|
|
44
31
|
}
|
|
45
32
|
configure(consumer) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
33
|
+
consumer
|
|
34
|
+
.apply((0, node_1.toNodeHandler)(this.authService.auth))
|
|
35
|
+
.forRoutes(this.options.basePath ?? "/api/auth/{*any}");
|
|
36
|
+
if (this.options.middleware?.register !== false) {
|
|
37
|
+
const proxy = consumer.apply(auth_middleware_1.AuthMiddleware);
|
|
38
|
+
if (this.options.middleware?.excludeRoutes) {
|
|
39
|
+
proxy.exclude(...this.options.middleware.excludeRoutes);
|
|
40
|
+
}
|
|
41
|
+
if (this.options.middleware?.includeRoutes) {
|
|
42
|
+
proxy.forRoutes(...this.options.middleware.includeRoutes);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
proxy.forRoutes("*");
|
|
46
|
+
}
|
|
57
47
|
}
|
|
58
48
|
}
|
|
59
49
|
};
|
|
60
50
|
exports.AuthModule = AuthModule;
|
|
61
51
|
exports.AuthModule = AuthModule = __decorate([
|
|
52
|
+
(0, common_1.Global)(),
|
|
62
53
|
(0, common_1.Module)({
|
|
63
54
|
imports: [request_context_1.RequestContextModule],
|
|
64
|
-
providers: [
|
|
65
|
-
|
|
55
|
+
providers: [
|
|
56
|
+
auth_service_1.AuthService,
|
|
57
|
+
auth_middleware_1.AuthMiddleware,
|
|
58
|
+
{
|
|
59
|
+
provide: auth_constants_1.AUTH_TOKEN,
|
|
60
|
+
inject: [auth_module_definition_1.MODULE_OPTIONS_TOKEN, core_1.MikroORM],
|
|
61
|
+
useFactory: (options, orm) => (0, better_auth_1.betterAuth)({
|
|
62
|
+
...options,
|
|
63
|
+
database: (0, mikro_orm_adapter_1.mikroOrmAdapter)({
|
|
64
|
+
orm,
|
|
65
|
+
entities: options.entities,
|
|
66
|
+
}),
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
exports: [auth_service_1.AuthService, auth_middleware_1.AuthMiddleware],
|
|
66
71
|
}),
|
|
67
|
-
__param(1, (0, common_1.Inject)(
|
|
68
|
-
|
|
69
|
-
__metadata("design:paramtypes", [core_2.HttpAdapterHost, Object, Object])
|
|
72
|
+
__param(1, (0, common_1.Inject)(auth_module_definition_1.MODULE_OPTIONS_TOKEN)),
|
|
73
|
+
__metadata("design:paramtypes", [auth_service_1.AuthService, Object])
|
|
70
74
|
], AuthModule);
|
|
71
75
|
//# sourceMappingURL=auth.module.js.map
|
package/dist/auth.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAA2C;AAC3C,gEAAkE;AAClE,
|
|
1
|
+
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAA2C;AAC3C,gEAAkE;AAClE,2CAMwB;AACxB,6CAAyC;AACzC,2CAAiD;AAEjD,oEAA+D;AAC/D,qDAA8C;AAC9C,uDAAmD;AACnD,qEAGkC;AAClC,iDAA6C;AAwBtC,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,gDAAuB;IACrD,YACmB,WAAwB,EAExB,OAA0B;QAE3C,KAAK,EAAE,CAAC;QAJS,gBAAW,GAAX,WAAW,CAAa;QAExB,YAAO,GAAP,OAAO,CAAmB;IAG7C,CAAC;IAED,SAAS,CAAC,QAA4B;QACpC,QAAQ;aACL,KAAK,CAAC,IAAA,oBAAa,EAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;aAC3C,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,kBAAkB,CAAC,CAAC;QAE1D,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,KAAK,KAAK,EAAE,CAAC;YAChD,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,gCAAc,CAAC,CAAC;YAE7C,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,aAAa,EAAE,CAAC;gBAC3C,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;YAC1D,CAAC;YAED,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,aAAa,EAAE,CAAC;gBAC3C,KAAK,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;YAC5D,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAA;AA5BY,gCAAU;qBAAV,UAAU;IArBtB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sCAAoB,CAAC;QAC/B,SAAS,EAAE;YACT,0BAAW;YACX,gCAAc;YACd;gBACE,OAAO,EAAE,2BAAU;gBACnB,MAAM,EAAE,CAAC,6CAAoB,EAAE,eAAQ,CAAC;gBACxC,UAAU,EAAE,CAAC,OAA0B,EAAE,GAAa,EAAE,EAAE,CACxD,IAAA,wBAAU,EAAC;oBACT,GAAG,OAAO;oBACV,QAAQ,EAAE,IAAA,mCAAe,EAAC;wBACxB,GAAG;wBACH,QAAQ,EAAE,OAAO,CAAC,QAAQ;qBAC3B,CAAC;iBACH,CAAC;aACL;SACF;QACD,OAAO,EAAE,CAAC,0BAAW,EAAE,gCAAc,CAAC;KACvC,CAAC;IAIG,WAAA,IAAA,eAAM,EAAC,6CAAoB,CAAC,CAAA;qCADC,0BAAW;GAFhC,UAAU,CA4BtB"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,7 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./auth.constants"), exports);
|
|
18
18
|
__exportStar(require("./auth.guard"), exports);
|
|
19
|
-
__exportStar(require("./auth.interceptor"), exports);
|
|
20
19
|
__exportStar(require("./auth.module"), exports);
|
|
21
20
|
__exportStar(require("./auth.transaction-context"), exports);
|
|
22
21
|
__exportStar(require("./auth-module-options.interface"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,+CAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,+CAA6B;AAC7B,gDAA8B;AAC9B,6DAA2C;AAC3C,kEAAgD;AAChD,+CAA6B;AAC7B,6CAA2B"}
|