@nest-boot/auth 7.9.1 → 7.9.3
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/adapters/mikro-orm-adapter.d.ts +4 -0
- package/dist/adapters/mikro-orm-adapter.js.map +1 -1
- package/dist/auth-module-options.interface.d.ts +9 -0
- package/dist/auth.constants.d.ts +2 -0
- package/dist/auth.constants.js +2 -0
- package/dist/auth.constants.js.map +1 -1
- package/dist/auth.guard.d.ts +15 -0
- package/dist/auth.guard.js +15 -0
- package/dist/auth.guard.js.map +1 -1
- package/dist/auth.middleware.d.ts +21 -0
- package/dist/auth.middleware.js +21 -0
- package/dist/auth.middleware.js.map +1 -1
- package/dist/auth.module-definition.d.ts +1 -1
- package/dist/auth.module-definition.js +2 -2
- package/dist/auth.module-definition.js.map +1 -1
- package/dist/auth.module.d.ts +28 -1
- package/dist/auth.module.js +33 -0
- package/dist/auth.module.js.map +1 -1
- package/dist/auth.service.d.ts +7 -0
- package/dist/auth.service.js +6 -0
- package/dist/auth.service.js.map +1 -1
- package/dist/auth.transaction-context.d.ts +24 -5
- package/dist/auth.transaction-context.js +16 -0
- package/dist/auth.transaction-context.js.map +1 -1
- package/dist/decorators/current-session.decorator.d.ts +1 -0
- package/dist/decorators/current-session.decorator.js +1 -0
- package/dist/decorators/current-session.decorator.js.map +1 -1
- package/dist/decorators/current-user.decorator.d.ts +1 -0
- package/dist/decorators/current-user.decorator.js +1 -0
- package/dist/decorators/current-user.decorator.js.map +1 -1
- package/dist/decorators/public.decorator.d.ts +1 -0
- package/dist/decorators/public.decorator.js +1 -0
- package/dist/decorators/public.decorator.js.map +1 -1
- package/dist/entities/account.entity.d.ts +20 -0
- package/dist/entities/account.entity.js +10 -0
- package/dist/entities/account.entity.js.map +1 -1
- package/dist/entities/session.entity.d.ts +15 -0
- package/dist/entities/session.entity.js +10 -0
- package/dist/entities/session.entity.js.map +1 -1
- package/dist/entities/user.entity.d.ts +14 -0
- package/dist/entities/user.entity.js +10 -0
- package/dist/entities/user.entity.js.map +1 -1
- package/dist/entities/verification.entity.d.ts +13 -0
- package/dist/entities/verification.entity.js +10 -0
- package/dist/entities/verification.entity.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +11 -6
|
@@ -10,9 +10,13 @@ export interface MikroOrmAdapterConfig {
|
|
|
10
10
|
* The entities to use for the adapter.
|
|
11
11
|
*/
|
|
12
12
|
entities: {
|
|
13
|
+
/** Account entity class. */
|
|
13
14
|
account: EntityClass<BaseAccount>;
|
|
15
|
+
/** Session entity class. */
|
|
14
16
|
session: EntityClass<BaseSession>;
|
|
17
|
+
/** User entity class. */
|
|
15
18
|
user: EntityClass<BaseUser>;
|
|
19
|
+
/** Verification entity class. */
|
|
16
20
|
verification: EntityClass<BaseVerification>;
|
|
17
21
|
};
|
|
18
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mikro-orm-adapter.js","sourceRoot":"","sources":["../../src/adapters/mikro-orm-adapter.ts"],"names":[],"mappings":";;;AACA,mDAI8B;
|
|
1
|
+
{"version":3,"file":"mikro-orm-adapter.js","sourceRoot":"","sources":["../../src/adapters/mikro-orm-adapter.ts"],"names":[],"mappings":";;;AACA,mDAI8B;AAiC9B,SAAS,sBAAsB,CAAC,KAAwB;IACtD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE;QAC9C,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,IAAI;gBACP,OAAO;oBACL,CAAC,KAAK,CAAC,EAAE;wBACP,GAAG,EAAE,KAAK;qBACX;iBACF,CAAC;YACJ,KAAK,IAAI;gBACP,OAAO;oBACL,CAAC,KAAK,CAAC,EAAE;wBACP,GAAG,EAAE,KAAK;qBACX;iBACF,CAAC;YACJ,KAAK,IAAI;gBACP,OAAO;oBACL,CAAC,KAAK,CAAC,EAAE;wBACP,GAA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AE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE;oBAC1D,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;wBACzD,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,sBAAsB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;wBAC1D,KAAK,EAAE,KAAK;wBACZ,MAAM,EAAE,MAAM,IAAI,CAAC;wBACnB,GAAG,CAAC,MAAM;4BACR,CAAC,CAAC;gCACE,OAAO,EAAE;oCACP,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,SAAS;iCACjC;6BACF;4BACH,CAAC,CAAC,EAAE,CAAC;qBACR,CAAC,CAAC;oBAEH,OAAO,MAAa,CAAC;gBACvB,CAAC;gBACD,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE;oBAChC,OAAO,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CACvB,cAAc,CAAC,KAAK,CAAC,EACrB,KAAK,CAAC,CAAC,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAClD,CAAC;gBACJ,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAjGW,QAAA,eAAe,mBAiG1B"}
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import { RouteInfo, Type } from "@nestjs/common/interfaces";
|
|
2
2
|
import { BetterAuthOptions } from "better-auth";
|
|
3
3
|
import { MikroOrmAdapterConfig } from "./adapters/mikro-orm-adapter";
|
|
4
|
+
/** Options for configuring auth middleware route registration. */
|
|
4
5
|
export interface AuthModuleMiddlewareOptions {
|
|
6
|
+
/** Whether to register the auth middleware (defaults to true). */
|
|
5
7
|
register?: boolean;
|
|
8
|
+
/** Routes to include in auth middleware processing. */
|
|
6
9
|
includeRoutes?: (string | RouteInfo | Type)[];
|
|
10
|
+
/** Routes to exclude from auth middleware processing. */
|
|
7
11
|
excludeRoutes?: (string | RouteInfo)[];
|
|
8
12
|
}
|
|
13
|
+
/** Configuration options for the AuthModule. */
|
|
9
14
|
export interface AuthModuleOptions extends Omit<BetterAuthOptions, "database"> {
|
|
15
|
+
/** Base path for the auth API endpoints. */
|
|
10
16
|
basePath?: string;
|
|
17
|
+
/** Entity classes used for authentication. */
|
|
11
18
|
entities: MikroOrmAdapterConfig["entities"];
|
|
19
|
+
/** Middleware registration options. */
|
|
12
20
|
middleware?: AuthModuleMiddlewareOptions;
|
|
21
|
+
/** Callback invoked after successful authentication. */
|
|
13
22
|
onAuthenticated?: () => void | Promise<void>;
|
|
14
23
|
}
|
package/dist/auth.constants.d.ts
CHANGED
package/dist/auth.constants.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IS_PUBLIC_KEY = exports.AUTH_TOKEN = void 0;
|
|
4
|
+
/** Injection token for the better-auth instance. */
|
|
4
5
|
exports.AUTH_TOKEN = Symbol("AUTH");
|
|
6
|
+
/** Metadata key used by the {@link Public} decorator to mark public routes. */
|
|
5
7
|
exports.IS_PUBLIC_KEY = Symbol("IS_PUBLIC_KEY");
|
|
6
8
|
//# sourceMappingURL=auth.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.constants.js","sourceRoot":"","sources":["../src/auth.constants.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"auth.constants.js","sourceRoot":"","sources":["../src/auth.constants.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAEzC,+EAA+E;AAClE,QAAA,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC"}
|
package/dist/auth.guard.d.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { CanActivate, ExecutionContext } from "@nestjs/common";
|
|
2
2
|
import { Reflector } from "@nestjs/core";
|
|
3
|
+
/**
|
|
4
|
+
* Guard that enforces authentication on routes.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Allows access if the route is marked with {@link Public}, otherwise
|
|
8
|
+
* requires a valid session in the request context.
|
|
9
|
+
*/
|
|
3
10
|
export declare class AuthGuard implements CanActivate {
|
|
4
11
|
protected readonly reflector: Reflector;
|
|
12
|
+
/** Creates a new AuthGuard instance.
|
|
13
|
+
* @param reflector - NestJS reflector for reading route metadata
|
|
14
|
+
*/
|
|
5
15
|
constructor(reflector: Reflector);
|
|
16
|
+
/**
|
|
17
|
+
* Determines whether the current request is allowed to proceed.
|
|
18
|
+
* @param context - The execution context of the current request
|
|
19
|
+
* @returns `true` if the route is public or the user has a valid session
|
|
20
|
+
*/
|
|
6
21
|
canActivate(context: ExecutionContext): boolean;
|
|
7
22
|
}
|
package/dist/auth.guard.js
CHANGED
|
@@ -15,10 +15,25 @@ const common_1 = require("@nestjs/common");
|
|
|
15
15
|
const core_1 = require("@nestjs/core");
|
|
16
16
|
const auth_constants_1 = require("./auth.constants");
|
|
17
17
|
const session_entity_1 = require("./entities/session.entity");
|
|
18
|
+
/**
|
|
19
|
+
* Guard that enforces authentication on routes.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Allows access if the route is marked with {@link Public}, otherwise
|
|
23
|
+
* requires a valid session in the request context.
|
|
24
|
+
*/
|
|
18
25
|
let AuthGuard = class AuthGuard {
|
|
26
|
+
/** Creates a new AuthGuard instance.
|
|
27
|
+
* @param reflector - NestJS reflector for reading route metadata
|
|
28
|
+
*/
|
|
19
29
|
constructor(reflector) {
|
|
20
30
|
this.reflector = reflector;
|
|
21
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Determines whether the current request is allowed to proceed.
|
|
34
|
+
* @param context - The execution context of the current request
|
|
35
|
+
* @returns `true` if the route is public or the user has a valid session
|
|
36
|
+
*/
|
|
22
37
|
canActivate(context) {
|
|
23
38
|
if (this.reflector.getAllAndOverride(auth_constants_1.IS_PUBLIC_KEY, [
|
|
24
39
|
context.getHandler(),
|
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,2CAA2E;AAC3E,uCAAyC;AAEzC,qDAAiD;AACjD,8DAAwD;
|
|
1
|
+
{"version":3,"file":"auth.guard.js","sourceRoot":"","sources":["../src/auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gEAA4D;AAC5D,2CAA2E;AAC3E,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;IACH,WAAW,CAAC,OAAyB;QACnC,IACE,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAU,8BAAa,EAAE;YACvD,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACnB,CAAC,EACF,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,CAAC,CAAC,gCAAc,CAAC,GAAG,CAAC,4BAAW,CAAC,CAAC;IAC3C,CAAC;CACF,CAAA;AAvBY,8BAAS;oBAAT,SAAS;IADrB,IAAA,mBAAU,GAAE;qCAK+B,gBAAS;GAJxC,SAAS,CAuBrB"}
|
|
@@ -3,11 +3,32 @@ import { NestMiddleware } from "@nestjs/common";
|
|
|
3
3
|
import { NextFunction, Request, Response } from "express";
|
|
4
4
|
import { AuthService } from "./auth.service";
|
|
5
5
|
import { AuthModuleOptions } from "./auth-module-options.interface";
|
|
6
|
+
/**
|
|
7
|
+
* Middleware that resolves the current user and session from the request.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Extracts the session token from headers via the better-auth API,
|
|
11
|
+
* loads the corresponding user and session entities, and stores
|
|
12
|
+
* them in the {@link RequestContext}.
|
|
13
|
+
*/
|
|
6
14
|
export declare class AuthMiddleware implements NestMiddleware {
|
|
7
15
|
private readonly options;
|
|
8
16
|
private readonly authService;
|
|
9
17
|
private readonly em;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new AuthMiddleware instance.
|
|
20
|
+
* @param options - Auth module configuration options
|
|
21
|
+
* @param authService - Service exposing the better-auth API
|
|
22
|
+
* @param em - MikroORM entity manager for loading user/session entities
|
|
23
|
+
*/
|
|
10
24
|
constructor(options: AuthModuleOptions, authService: AuthService, em: EntityManager);
|
|
25
|
+
/** Retrieves the session from the request headers via the better-auth API. */
|
|
11
26
|
private getSession;
|
|
27
|
+
/**
|
|
28
|
+
* Resolves authentication state and attaches user/session to the request context.
|
|
29
|
+
* @param req - Express request object
|
|
30
|
+
* @param res - Express response object
|
|
31
|
+
* @param next - Express next function
|
|
32
|
+
*/
|
|
12
33
|
use(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
13
34
|
}
|
package/dist/auth.middleware.js
CHANGED
|
@@ -19,12 +19,27 @@ const common_1 = require("@nestjs/common");
|
|
|
19
19
|
const auth_module_definition_1 = require("./auth.module-definition");
|
|
20
20
|
const auth_service_1 = require("./auth.service");
|
|
21
21
|
const entities_1 = require("./entities");
|
|
22
|
+
/**
|
|
23
|
+
* Middleware that resolves the current user and session from the request.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Extracts the session token from headers via the better-auth API,
|
|
27
|
+
* loads the corresponding user and session entities, and stores
|
|
28
|
+
* them in the {@link RequestContext}.
|
|
29
|
+
*/
|
|
22
30
|
let AuthMiddleware = class AuthMiddleware {
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new AuthMiddleware instance.
|
|
33
|
+
* @param options - Auth module configuration options
|
|
34
|
+
* @param authService - Service exposing the better-auth API
|
|
35
|
+
* @param em - MikroORM entity manager for loading user/session entities
|
|
36
|
+
*/
|
|
23
37
|
constructor(options, authService, em) {
|
|
24
38
|
this.options = options;
|
|
25
39
|
this.authService = authService;
|
|
26
40
|
this.em = em;
|
|
27
41
|
}
|
|
42
|
+
/** Retrieves the session from the request headers via the better-auth API. */
|
|
28
43
|
async getSession(req) {
|
|
29
44
|
return await this.authService.api.getSession({
|
|
30
45
|
headers: Object.entries(req.headers).reduce((headers, [key, value]) => {
|
|
@@ -42,6 +57,12 @@ let AuthMiddleware = class AuthMiddleware {
|
|
|
42
57
|
}, new Headers()),
|
|
43
58
|
});
|
|
44
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Resolves authentication state and attaches user/session to the request context.
|
|
62
|
+
* @param req - Express request object
|
|
63
|
+
* @param res - Express response object
|
|
64
|
+
* @param next - Express next function
|
|
65
|
+
*/
|
|
45
66
|
async use(req, res, next) {
|
|
46
67
|
const data = await this.getSession(req);
|
|
47
68
|
if (!data) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.middleware.js","sourceRoot":"","sources":["../src/auth.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAAgD;AAChD,gEAA4D;AAC5D,2CAA0E;AAG1E,qEAAgE;AAChE,iDAA6C;AAE7C,yCAAmD;
|
|
1
|
+
{"version":3,"file":"auth.middleware.js","sourceRoot":"","sources":["../src/auth.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAAgD;AAChD,gEAA4D;AAC5D,2CAA0E;AAG1E,qEAAgE;AAChE,iDAA6C;AAE7C,yCAAmD;AAEnD;;;;;;;GAOG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB;;;;;OAKG;IACH,YAEmB,OAA0B,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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,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC;YACpB,gCAAc,CAAC,GAAG,CAAC,mBAAQ,EAAE,IAAI,CAAC,CAAC;YACnC,gCAAc,CAAC,GAAG,CAAC,sBAAW,EAAE,OAAO,CAAC,CAAC;YAEzC,gCAAc,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAsB,EAAE,IAAI,CAAC,CAAC;YACvE,gCAAc,CAAC,GAAG,CAChB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAA4B,EAClD,OAAO,CACR,CAAC;YAEF,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;QACzC,CAAC;QAED,IAAI,EAAE,CAAC;IACT,CAAC;CACF,CAAA;AArEY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;IASR,WAAA,IAAA,eAAM,EAAC,6CAAoB,CAAC,CAAA;6CAEC,0BAAW;QACpB,oBAAa;GAXzB,cAAc,CAqE1B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type AuthModuleOptions } from "./auth-module-options.interface";
|
|
2
|
-
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<AuthModuleOptions, "forRoot", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol
|
|
2
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<AuthModuleOptions, "forRoot", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: AuthModuleOptions & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<AuthModuleOptions, "create"> & Partial<{}>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = void 0;
|
|
4
|
+
exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = void 0;
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
_a = new common_1.ConfigurableModuleBuilder()
|
|
7
7
|
.setClassMethodName("forRoot")
|
|
8
|
-
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN;
|
|
8
|
+
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
|
|
9
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,
|
|
1
|
+
{"version":3,"file":"auth.module-definition.js","sourceRoot":"","sources":["../src/auth.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAI9C,KAKT,IAAI,kCAAyB,EAAqB;KACnD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,KAAK,EAAE,EANR,+BAAuB,+BACvB,4BAAoB,4BACpB,oBAAY,oBACZ,0BAAkB,yBAGT"}
|
package/dist/auth.module.d.ts
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
import { MiddlewareManager } from "@nest-boot/middleware";
|
|
2
|
+
import { type DynamicModule } from "@nestjs/common";
|
|
2
3
|
import { Auth } from "better-auth";
|
|
3
4
|
import { AuthMiddleware } from "./auth.middleware";
|
|
4
|
-
import { ConfigurableModuleClass } from "./auth.module-definition";
|
|
5
|
+
import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from "./auth.module-definition";
|
|
5
6
|
import { AuthModuleOptions } from "./auth-module-options.interface";
|
|
7
|
+
/**
|
|
8
|
+
* Authentication module based on better-auth.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Provides authentication services including session management, middleware registration,
|
|
12
|
+
* and MikroORM-based persistence via the better-auth adapter.
|
|
13
|
+
*/
|
|
6
14
|
export declare class AuthModule extends ConfigurableModuleClass {
|
|
7
15
|
private readonly auth;
|
|
8
16
|
private readonly options;
|
|
9
17
|
private readonly middlewareManager;
|
|
10
18
|
private readonly authMiddleware;
|
|
19
|
+
/**
|
|
20
|
+
* Registers the AuthModule with the given options.
|
|
21
|
+
* @param options - Configuration options including secret and middleware settings
|
|
22
|
+
* @returns Dynamic module configuration
|
|
23
|
+
*/
|
|
24
|
+
static forRoot(options: typeof OPTIONS_TYPE): DynamicModule;
|
|
25
|
+
/**
|
|
26
|
+
* Registers the AuthModule asynchronously with factory functions.
|
|
27
|
+
* @param options - Async configuration options
|
|
28
|
+
* @returns Dynamic module configuration
|
|
29
|
+
*/
|
|
30
|
+
static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new AuthModule instance.
|
|
33
|
+
* @param auth - The better-auth instance
|
|
34
|
+
* @param options - Auth module configuration options
|
|
35
|
+
* @param middlewareManager - Middleware manager for registering auth middleware
|
|
36
|
+
* @param authMiddleware - The auth middleware instance
|
|
37
|
+
*/
|
|
11
38
|
constructor(auth: Auth, options: AuthModuleOptions, middlewareManager: MiddlewareManager, authMiddleware: AuthMiddleware);
|
|
12
39
|
}
|
package/dist/auth.module.js
CHANGED
|
@@ -25,7 +25,37 @@ const auth_middleware_1 = require("./auth.middleware");
|
|
|
25
25
|
const auth_module_definition_1 = require("./auth.module-definition");
|
|
26
26
|
const auth_service_1 = require("./auth.service");
|
|
27
27
|
const estimate_entropy_1 = require("./utils/estimate-entropy");
|
|
28
|
+
/**
|
|
29
|
+
* Authentication module based on better-auth.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Provides authentication services including session management, middleware registration,
|
|
33
|
+
* and MikroORM-based persistence via the better-auth adapter.
|
|
34
|
+
*/
|
|
28
35
|
let AuthModule = class AuthModule extends auth_module_definition_1.ConfigurableModuleClass {
|
|
36
|
+
/**
|
|
37
|
+
* Registers the AuthModule with the given options.
|
|
38
|
+
* @param options - Configuration options including secret and middleware settings
|
|
39
|
+
* @returns Dynamic module configuration
|
|
40
|
+
*/
|
|
41
|
+
static forRoot(options) {
|
|
42
|
+
return super.forRoot(options);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Registers the AuthModule asynchronously with factory functions.
|
|
46
|
+
* @param options - Async configuration options
|
|
47
|
+
* @returns Dynamic module configuration
|
|
48
|
+
*/
|
|
49
|
+
static forRootAsync(options) {
|
|
50
|
+
return super.forRootAsync(options);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new AuthModule instance.
|
|
54
|
+
* @param auth - The better-auth instance
|
|
55
|
+
* @param options - Auth module configuration options
|
|
56
|
+
* @param middlewareManager - Middleware manager for registering auth middleware
|
|
57
|
+
* @param authMiddleware - The auth middleware instance
|
|
58
|
+
*/
|
|
29
59
|
constructor(auth, options, middlewareManager, authMiddleware) {
|
|
30
60
|
super();
|
|
31
61
|
this.auth = auth;
|
|
@@ -88,6 +118,9 @@ exports.AuthModule = AuthModule = __decorate([
|
|
|
88
118
|
return (0, better_auth_1.betterAuth)({
|
|
89
119
|
baseURL: process.env.AUTH_URL ?? process.env.APP_URL,
|
|
90
120
|
secret,
|
|
121
|
+
account: {
|
|
122
|
+
skipStateCookieCheck: true,
|
|
123
|
+
},
|
|
91
124
|
...options,
|
|
92
125
|
database: (0, mikro_orm_adapter_1.mikroOrmAdapter)({
|
|
93
126
|
orm,
|
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,sDAA4E;AAC5E,gEAGoC;AACpC,
|
|
1
|
+
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAA2C;AAC3C,sDAA4E;AAC5E,gEAGoC;AACpC,2CAA4E;AAC5E,6CAA+C;AAC/C,2CAAiD;AAEjD,oEAA+D;AAC/D,qDAA8C;AAC9C,uDAAmD;AACnD,qEAKkC;AAClC,iDAA6C;AAE7C,+DAA2D;AAE3D;;;;;;GAMG;AA0DI,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,gDAAuB;IACrD;;;;OAIG;IACH,MAAM,CAAU,OAAO,CAAC,OAA4B;QAClD,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAU,YAAY,CAC1B,OAAkC;QAElC,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;OAMG;IACH,YAEmB,IAAU,EAEV,OAA0B,EAC1B,iBAAoC,EACpC,cAA8B;QAE/C,KAAK,EAAE,CAAC;QANS,SAAI,GAAJ,IAAI,CAAM;QAEV,YAAO,GAAP,OAAO,CAAmB;QAC1B,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,mBAAc,GAAd,cAAc,CAAgB;QAI/C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,YAAY,CAAC;QAEv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,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;oBAEtE,IAAI,CAAC,MAAM,EAAE,CAAC;wBACZ,MAAM,IAAI,KAAK,CACb,4BAA4B;4BAC1B,gFAAgF;4BAChF,kCAAkC;4BAClC,oFAAoF,CACvF,CAAC;oBACJ,CAAC;oBAED,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;wBACvB,MAAM,IAAI,KAAK,CACb,oDAAoD;4BAClD,gFAAgF;4BAChF,kCAAkC;4BAClC,oFAAoF,CACvF,CAAC;oBACJ,CAAC;oBAED,IAAI,IAAA,kCAAe,EAAC,MAAM,CAAC,GAAG,GAAG,EAAE,CAAC;wBAClC,MAAM,IAAI,KAAK,CACb,oCAAoC;4BAClC,mDAAmD;4BACnD,kCAAkC;4BAClC,oFAAoF,CACvF,CAAC;oBACJ,CAAC;oBAED,OAAO,IAAA,wBAAU,EAAC;wBAChB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO;wBACpD,MAAM;wBACN,OAAO,EAAE;4BACP,oBAAoB,EAAE,IAAI;yBAC3B;wBACD,GAAG,OAAO;wBACV,QAAQ,EAAE,IAAA,mCAAe,EAAC;4BACxB,GAAG;4BACH,QAAQ,EAAE,OAAO,CAAC,QAAQ;yBAC3B,CAAC;qBACH,CAAC,CAAC;gBACL,CAAC;aACF;SACF;QACD,OAAO,EAAE,CAAC,0BAAW,CAAC;KACvB,CAAC;IA8BG,WAAA,IAAA,eAAM,EAAC,2BAAU,CAAC,CAAA;IAElB,WAAA,IAAA,eAAM,EAAC,6CAAoB,CAAC,CAAA;qDAEO,8BAAiB;QACpB,gCAAc;GAlCtC,UAAU,CA+DtB"}
|
package/dist/auth.service.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { Auth } from "better-auth";
|
|
2
|
+
/** Service exposing the better-auth API to the application. */
|
|
2
3
|
export declare class AuthService {
|
|
4
|
+
/** @internal */
|
|
3
5
|
private readonly auth;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new AuthService instance.
|
|
8
|
+
* @param auth - The better-auth instance
|
|
9
|
+
*/
|
|
4
10
|
constructor(auth: Auth);
|
|
11
|
+
/** The better-auth API interface for session and user management. */
|
|
5
12
|
get api(): import("better-auth/*").InferAPI<{
|
|
6
13
|
readonly ok: import("better-auth/*").StrictEndpoint<"/ok", {
|
|
7
14
|
method: "GET";
|
package/dist/auth.service.js
CHANGED
|
@@ -15,10 +15,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.AuthService = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const auth_constants_1 = require("./auth.constants");
|
|
18
|
+
/** Service exposing the better-auth API to the application. */
|
|
18
19
|
let AuthService = class AuthService {
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new AuthService instance.
|
|
22
|
+
* @param auth - The better-auth instance
|
|
23
|
+
*/
|
|
19
24
|
constructor(auth) {
|
|
20
25
|
this.auth = auth;
|
|
21
26
|
}
|
|
27
|
+
/** The better-auth API interface for session and user management. */
|
|
22
28
|
get api() {
|
|
23
29
|
return this.auth.api;
|
|
24
30
|
}
|
package/dist/auth.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../src/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwC;AAGxC,qDAA8C;AAE9C,IAAa,WAAW,GAAxB,MAAa,WAAW;IACtB,
|
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../src/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwC;AAGxC,qDAA8C;AAE9C,+DAA+D;AAC/D,IAAa,WAAW,GAAxB,MAAa,WAAW;IACtB;;;OAGG;IACH,YAGmB,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;IAC1B,CAAC;IAEJ,qEAAqE;IACrE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IACvB,CAAC;CACF,CAAA;AAfY,kCAAW;sBAAX,WAAW;IAMnB,WAAA,IAAA,eAAM,EAAC,2BAAU,CAAC,CAAA;;GANV,WAAW,CAevB"}
|
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
type
|
|
1
|
+
/** Union of all lowercase letter characters (a–z). */
|
|
2
|
+
export type LowercaseLetter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
|
|
3
|
+
/** Characters allowed in snake_case identifiers (lowercase letters and underscore). */
|
|
4
|
+
export type ValidChar = LowercaseLetter | "_";
|
|
5
|
+
/** Recursively validates that a string contains only valid snake_case characters. */
|
|
6
|
+
export type IsValidSnakeCase<S extends string> = S extends `${infer First}${infer Rest}` ? First extends ValidChar ? IsValidSnakeCase<Rest> : false : true;
|
|
7
|
+
/** Ensures a string literal is a valid snake_case identifier. */
|
|
8
|
+
export type SnakeCase<S extends string> = S extends "" ? never : S extends `_${string}` | `${string}_` ? never : S extends `${string}__${string}` ? never : IsValidSnakeCase<S> extends true ? S : never;
|
|
9
|
+
/**
|
|
10
|
+
* Stores key-value pairs for PostgreSQL transaction-level auth context.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Values set here are emitted as `set_config('auth.<key>', '<value>', true)` SQL
|
|
14
|
+
* statements, enabling row-level security policies to access auth state.
|
|
15
|
+
*/
|
|
5
16
|
export declare class AuthTransactionContext {
|
|
17
|
+
/** Internal storage for transaction context key-value pairs. @internal */
|
|
6
18
|
private readonly ctx;
|
|
19
|
+
/**
|
|
20
|
+
* Sets a snake_case key-value pair in the transaction context.
|
|
21
|
+
* @param key - Must be a valid snake_case string
|
|
22
|
+
* @param value - The string value to associate with the key
|
|
23
|
+
* @returns This instance for chaining
|
|
24
|
+
*/
|
|
7
25
|
set<S extends string>(key: SnakeCase<S>, value: string): this;
|
|
26
|
+
/** Returns all stored key-value pairs as an array of `[key, value]` tuples. */
|
|
8
27
|
entries(): [string, string][];
|
|
28
|
+
/** Generates a SQL statement that sets all stored values as PostgreSQL transaction-local config variables. */
|
|
9
29
|
toSQL(): string;
|
|
10
30
|
}
|
|
11
|
-
export {};
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthTransactionContext = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Stores key-value pairs for PostgreSQL transaction-level auth context.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Values set here are emitted as `set_config('auth.<key>', '<value>', true)` SQL
|
|
9
|
+
* statements, enabling row-level security policies to access auth state.
|
|
10
|
+
*/
|
|
4
11
|
class AuthTransactionContext {
|
|
5
12
|
constructor() {
|
|
13
|
+
/** Internal storage for transaction context key-value pairs. @internal */
|
|
6
14
|
this.ctx = new Map();
|
|
7
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Sets a snake_case key-value pair in the transaction context.
|
|
18
|
+
* @param key - Must be a valid snake_case string
|
|
19
|
+
* @param value - The string value to associate with the key
|
|
20
|
+
* @returns This instance for chaining
|
|
21
|
+
*/
|
|
8
22
|
set(key, value) {
|
|
9
23
|
if (!/^[a-z]+(_[a-z]+)*$/.test(key)) {
|
|
10
24
|
throw new Error(`Key must only contain lowercase letters and underscores, cannot start/end with underscore, and cannot have consecutive underscores: ${key}`);
|
|
@@ -12,9 +26,11 @@ class AuthTransactionContext {
|
|
|
12
26
|
this.ctx.set(key, value);
|
|
13
27
|
return this;
|
|
14
28
|
}
|
|
29
|
+
/** Returns all stored key-value pairs as an array of `[key, value]` tuples. */
|
|
15
30
|
entries() {
|
|
16
31
|
return Array.from(this.ctx.entries());
|
|
17
32
|
}
|
|
33
|
+
/** Generates a SQL statement that sets all stored values as PostgreSQL transaction-local config variables. */
|
|
18
34
|
toSQL() {
|
|
19
35
|
return /* SQL */ `SELECT ${Array.from(this.ctx.entries())
|
|
20
36
|
.map(([key, value]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.transaction-context.js","sourceRoot":"","sources":["../src/auth.transaction-context.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"auth.transaction-context.js","sourceRoot":"","sources":["../src/auth.transaction-context.ts"],"names":[],"mappings":";;;AAmDA;;;;;;GAMG;AACH,MAAa,sBAAsB;IAAnC;QACE,0EAA0E;QACzD,QAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IAgCnD,CAAC;IA9BC;;;;;OAKG;IACH,GAAG,CAAmB,GAAiB,EAAE,KAAa;QACpD,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACb,uIAAuI,GAAG,EAAE,CAC7I,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,+EAA+E;IAC/E,OAAO;QACL,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,8GAA8G;IAC9G,KAAK;QACH,OAAO,SAAS,CAAC,UAAU,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;aACtD,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACpB,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC/C,OAAO,SAAS,CAAC,oBAAoB,GAAG,OAAO,YAAY,UAAU,CAAC;QACxE,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAClB,CAAC;CACF;AAlCD,wDAkCC"}
|
|
@@ -4,5 +4,6 @@ exports.CurrentSession = void 0;
|
|
|
4
4
|
const request_context_1 = require("@nest-boot/request-context");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const session_entity_1 = require("../entities/session.entity");
|
|
7
|
+
/** Parameter decorator that injects the current {@link BaseSession} from the request context. */
|
|
7
8
|
exports.CurrentSession = (0, common_1.createParamDecorator)(() => request_context_1.RequestContext.get(session_entity_1.BaseSession));
|
|
8
9
|
//# sourceMappingURL=current-session.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"current-session.decorator.js","sourceRoot":"","sources":["../../src/decorators/current-session.decorator.ts"],"names":[],"mappings":";;;AAAA,gEAA4D;AAC5D,2CAAsD;AAEtD,+DAAyD;
|
|
1
|
+
{"version":3,"file":"current-session.decorator.js","sourceRoot":"","sources":["../../src/decorators/current-session.decorator.ts"],"names":[],"mappings":";;;AAAA,gEAA4D;AAC5D,2CAAsD;AAEtD,+DAAyD;AAEzD,iGAAiG;AACpF,QAAA,cAAc,GAAG,IAAA,6BAAoB,EAAC,GAAG,EAAE,CACtD,gCAAc,CAAC,GAAG,CAAC,4BAAW,CAAC,CAChC,CAAC"}
|
|
@@ -4,5 +4,6 @@ exports.CurrentUser = void 0;
|
|
|
4
4
|
const request_context_1 = require("@nest-boot/request-context");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const user_entity_1 = require("../entities/user.entity");
|
|
7
|
+
/** Parameter decorator that injects the current {@link BaseUser} from the request context. */
|
|
7
8
|
exports.CurrentUser = (0, common_1.createParamDecorator)(() => request_context_1.RequestContext.get(user_entity_1.BaseUser));
|
|
8
9
|
//# sourceMappingURL=current-user.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"current-user.decorator.js","sourceRoot":"","sources":["../../src/decorators/current-user.decorator.ts"],"names":[],"mappings":";;;AAAA,gEAA4D;AAC5D,2CAAsD;AAEtD,yDAAmD;
|
|
1
|
+
{"version":3,"file":"current-user.decorator.js","sourceRoot":"","sources":["../../src/decorators/current-user.decorator.ts"],"names":[],"mappings":";;;AAAA,gEAA4D;AAC5D,2CAAsD;AAEtD,yDAAmD;AAEnD,8FAA8F;AACjF,QAAA,WAAW,GAAG,IAAA,6BAAoB,EAAC,GAAG,EAAE,CACnD,gCAAc,CAAC,GAAG,CAAC,sBAAQ,CAAC,CAC7B,CAAC"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Public = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const auth_constants_1 = require("../auth.constants");
|
|
6
|
+
/** Decorator that marks a route as public, bypassing the {@link AuthGuard}. */
|
|
6
7
|
const Public = (value = true) => (0, common_1.SetMetadata)(auth_constants_1.IS_PUBLIC_KEY, value);
|
|
7
8
|
exports.Public = Public;
|
|
8
9
|
//# sourceMappingURL=public.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public.decorator.js","sourceRoot":"","sources":["../../src/decorators/public.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,sDAAkD;
|
|
1
|
+
{"version":3,"file":"public.decorator.js","sourceRoot":"","sources":["../../src/decorators/public.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,sDAAkD;AAElD,+EAA+E;AACxE,MAAM,MAAM,GAAG,CAAC,KAAK,GAAG,IAAI,EAAE,EAAE,CAAC,IAAA,oBAAW,EAAC,8BAAa,EAAE,KAAK,CAAC,CAAC;AAA7D,QAAA,MAAM,UAAuD"}
|
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
import { BaseEntity, Opt } from "@mikro-orm/core";
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base entity for OAuth/credential account records.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Maps to the better-auth `account` model. Each account links a provider
|
|
7
|
+
* (e.g. Google, GitHub, credentials) to a {@link BaseUser}.
|
|
8
|
+
*/
|
|
2
9
|
export declare abstract class BaseAccount extends BaseEntity {
|
|
10
|
+
/** Primary key (UUID v4, auto-generated). */
|
|
3
11
|
id: Opt<string>;
|
|
12
|
+
/** Provider-scoped account identifier. */
|
|
4
13
|
accountId: string;
|
|
14
|
+
/** Authentication provider identifier (e.g. `"google"`, `"credential"`). */
|
|
5
15
|
providerId: string;
|
|
16
|
+
/** Foreign key referencing the owning {@link BaseUser}. */
|
|
6
17
|
userId: string;
|
|
18
|
+
/** OAuth access token, if available. */
|
|
7
19
|
accessToken?: Opt<string>;
|
|
20
|
+
/** OAuth refresh token, if available. */
|
|
8
21
|
refreshToken?: Opt<string>;
|
|
22
|
+
/** OpenID Connect ID token, if available. */
|
|
9
23
|
idToken?: Opt<string>;
|
|
24
|
+
/** Expiration timestamp of the access token. */
|
|
10
25
|
accessTokenExpiresAt?: Opt<Date>;
|
|
26
|
+
/** Expiration timestamp of the refresh token. */
|
|
11
27
|
refreshTokenExpiresAt?: Opt<Date>;
|
|
28
|
+
/** OAuth scopes granted to this account. */
|
|
12
29
|
scope?: Opt<string>;
|
|
30
|
+
/** Hashed password for credential-based accounts. */
|
|
13
31
|
password?: Opt<string>;
|
|
32
|
+
/** Timestamp when the account was created. */
|
|
14
33
|
createdAt: Opt<Date>;
|
|
34
|
+
/** Timestamp of the last update. */
|
|
15
35
|
updatedAt: Opt<Date>;
|
|
16
36
|
}
|
|
@@ -12,11 +12,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.BaseAccount = void 0;
|
|
13
13
|
const core_1 = require("@mikro-orm/core");
|
|
14
14
|
const crypto_1 = require("crypto");
|
|
15
|
+
/**
|
|
16
|
+
* Abstract base entity for OAuth/credential account records.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Maps to the better-auth `account` model. Each account links a provider
|
|
20
|
+
* (e.g. Google, GitHub, credentials) to a {@link BaseUser}.
|
|
21
|
+
*/
|
|
15
22
|
let BaseAccount = class BaseAccount extends core_1.BaseEntity {
|
|
16
23
|
constructor() {
|
|
17
24
|
super(...arguments);
|
|
25
|
+
/** Primary key (UUID v4, auto-generated). */
|
|
18
26
|
this.id = (0, crypto_1.randomUUID)();
|
|
27
|
+
/** Timestamp when the account was created. */
|
|
19
28
|
this.createdAt = new Date();
|
|
29
|
+
/** Timestamp of the last update. */
|
|
20
30
|
this.updatedAt = new Date();
|
|
21
31
|
}
|
|
22
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.entity.js","sourceRoot":"","sources":["../../src/entities/account.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CASyB;AACzB,mCAAoC;
|
|
1
|
+
{"version":3,"file":"account.entity.js","sourceRoot":"","sources":["../../src/entities/account.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CASyB;AACzB,mCAAoC;AAEpC;;;;;;GAMG;AAEI,IAAe,WAAW,GAA1B,MAAe,WAAY,SAAQ,iBAAU;IAA7C;;QACL,6CAA6C;QAE7C,OAAE,GAAgB,IAAA,mBAAU,GAAE,CAAC;QA8C/B,8CAA8C;QAE9C,cAAS,GAAc,IAAI,IAAI,EAAE,CAAC;QAElC,oCAAoC;QAMpC,cAAS,GAAc,IAAI,IAAI,EAAE,CAAC;IACpC,CAAC;CAAA,CAAA;AA5DqB,kCAAW;AAG/B;IADC,IAAA,iBAAU,EAAC,EAAE,IAAI,EAAE,QAAC,CAAC,IAAI,EAAE,CAAC;;uCACE;AAI/B;IADC,IAAA,eAAQ,EAAC,EAAE,IAAI,EAAE,QAAC,CAAC,IAAI,EAAE,CAAC;;8CACR;AAInB;IADC,IAAA,eAAQ,EAAC,EA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