@anarchitects/auth-nest 0.5.1 → 0.6.1
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/README.md +102 -61
- package/package.json +25 -5
- package/src/application/application.module.js +61 -36
- package/src/application/application.module.js.map +1 -1
- package/src/application/index.d.ts +0 -2
- package/src/application/index.js +0 -2
- package/src/application/index.js.map +1 -1
- package/src/application/ports/auth-account.repository.d.ts +18 -0
- package/src/application/ports/auth-account.repository.js +12 -0
- package/src/application/ports/auth-account.repository.js.map +1 -0
- package/src/{infrastructure-persistence/repositories → application/ports}/auth-user.repository.d.ts +1 -2
- package/src/application/ports/auth-user.repository.js.map +1 -0
- package/src/application/resource-authorization.types.d.ts +1 -16
- package/src/application/services/auth-engine.port.d.ts +22 -17
- package/src/application/services/auth-engine.port.js.map +1 -1
- package/src/application/services/auth-orchestration.service.d.ts +15 -10
- package/src/application/services/auth-orchestration.service.js +78 -61
- package/src/application/services/auth-orchestration.service.js.map +1 -1
- package/src/application/services/auth.service.d.ts +10 -7
- package/src/application/services/auth.service.js.map +1 -1
- package/src/application/services/better-auth-database.port.d.ts +3 -0
- package/src/application/services/better-auth-database.port.js +12 -0
- package/src/application/services/better-auth-database.port.js.map +1 -0
- package/src/application/services/policies.service.d.ts +1 -1
- package/src/application/services/policies.service.js +1 -1
- package/src/application/services/policies.service.js.map +1 -1
- package/src/application/services/resource-authorization.d.ts +1 -1
- package/src/auth.module.js +29 -3
- package/src/auth.module.js.map +1 -1
- package/src/config/auth.config.d.ts +62 -48
- package/src/config/auth.config.js +82 -76
- package/src/config/auth.config.js.map +1 -1
- package/src/config/index.d.ts +1 -0
- package/src/config/index.js +1 -0
- package/src/config/index.js.map +1 -1
- package/src/config/module-options.d.ts +69 -49
- package/src/config/module-options.js +79 -50
- package/src/config/module-options.js.map +1 -1
- package/src/config/resource-authorization.types.d.ts +16 -0
- package/src/config/resource-authorization.types.js +3 -0
- package/src/config/resource-authorization.types.js.map +1 -0
- package/src/infrastructure-engine/better-auth/better-auth-auth-engine.adapter.d.ts +32 -10
- package/src/infrastructure-engine/better-auth/better-auth-auth-engine.adapter.js +190 -90
- package/src/infrastructure-engine/better-auth/better-auth-auth-engine.adapter.js.map +1 -1
- package/src/infrastructure-engine/better-auth/better-auth-options.d.ts +21 -0
- package/src/infrastructure-engine/better-auth/better-auth-options.js +94 -0
- package/src/infrastructure-engine/better-auth/better-auth-options.js.map +1 -0
- package/src/infrastructure-engine/better-auth/better-auth-typeorm-adapter-persistence.adapter.d.ts +14 -0
- package/src/infrastructure-engine/better-auth/better-auth-typeorm-adapter-persistence.adapter.js +62 -0
- package/src/infrastructure-engine/better-auth/better-auth-typeorm-adapter-persistence.adapter.js.map +1 -0
- package/src/infrastructure-engine/better-auth/better-auth.module-loader.d.ts +6 -0
- package/src/infrastructure-engine/better-auth/better-auth.module-loader.js +9 -1
- package/src/infrastructure-engine/better-auth/better-auth.module-loader.js.map +1 -1
- package/src/infrastructure-engine/better-auth/plugins/jwt/better-auth-jwt-plugin.service.d.ts +21 -0
- package/src/infrastructure-engine/{legacy-jwt-auth-engine.adapter.js → better-auth/plugins/jwt/better-auth-jwt-plugin.service.js} +31 -63
- package/src/infrastructure-engine/better-auth/plugins/jwt/better-auth-jwt-plugin.service.js.map +1 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/better-auth-jwt-typeorm-support.module.d.ts +2 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/better-auth-jwt-typeorm-support.module.js +26 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/better-auth-jwt-typeorm-support.module.js.map +1 -0
- package/src/{infrastructure-persistence/entities → infrastructure-engine/better-auth/plugins/jwt}/invalidated-token.entity.js +1 -1
- package/src/infrastructure-engine/better-auth/plugins/jwt/invalidated-token.entity.js.map +1 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/jwt-auth-plugin.controller.d.ts +10 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/jwt-auth-plugin.controller.js +65 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/jwt-auth-plugin.controller.js.map +1 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/jwt-token-invalidation.repository.d.ts +4 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/jwt-token-invalidation.repository.js +12 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/jwt-token-invalidation.repository.js.map +1 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/typeorm-jwt-token-invalidation.repository.d.ts +9 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/typeorm-jwt-token-invalidation.repository.js +33 -0
- package/src/infrastructure-engine/better-auth/plugins/jwt/typeorm-jwt-token-invalidation.repository.js.map +1 -0
- package/src/infrastructure-engine/better-auth/plugins/passkeys/better-auth-passkeys-typeorm-support.module.d.ts +2 -0
- package/src/infrastructure-engine/better-auth/plugins/passkeys/better-auth-passkeys-typeorm-support.module.js +17 -0
- package/src/infrastructure-engine/better-auth/plugins/passkeys/better-auth-passkeys-typeorm-support.module.js.map +1 -0
- package/src/infrastructure-engine/better-auth/plugins/passkeys/migrations/1760200001000-create-better-auth-passkeys-table.d.ts +6 -0
- package/src/infrastructure-engine/better-auth/plugins/passkeys/migrations/1760200001000-create-better-auth-passkeys-table.js +83 -0
- package/src/infrastructure-engine/better-auth/plugins/passkeys/migrations/1760200001000-create-better-auth-passkeys-table.js.map +1 -0
- package/src/infrastructure-engine/better-auth/plugins/passkeys/passkey.entity.d.ts +14 -0
- package/src/infrastructure-engine/better-auth/plugins/passkeys/passkey.entity.js +71 -0
- package/src/infrastructure-engine/better-auth/plugins/passkeys/passkey.entity.js.map +1 -0
- package/src/infrastructure-persistence/entities/account.entity.d.ts +16 -0
- package/src/infrastructure-persistence/entities/account.entity.js +81 -0
- package/src/infrastructure-persistence/entities/account.entity.js.map +1 -0
- package/src/infrastructure-persistence/entities/session.entity.d.ts +11 -0
- package/src/infrastructure-persistence/entities/session.entity.js +58 -0
- package/src/infrastructure-persistence/entities/session.entity.js.map +1 -0
- package/src/infrastructure-persistence/entities/user.entity.d.ts +3 -4
- package/src/infrastructure-persistence/entities/user.entity.js +5 -9
- package/src/infrastructure-persistence/entities/user.entity.js.map +1 -1
- package/src/infrastructure-persistence/entities/verification.entity.d.ts +9 -0
- package/src/infrastructure-persistence/entities/verification.entity.js +50 -0
- package/src/infrastructure-persistence/entities/verification.entity.js.map +1 -0
- package/src/infrastructure-persistence/index.d.ts +1 -2
- package/src/infrastructure-persistence/index.js +1 -2
- package/src/infrastructure-persistence/index.js.map +1 -1
- package/src/infrastructure-persistence/migrations/1720200000000-create-auth-schema.js +189 -93
- package/src/infrastructure-persistence/migrations/1720200000000-create-auth-schema.js.map +1 -1
- package/src/infrastructure-persistence/persistence.module-definition.d.ts +1 -1
- package/src/infrastructure-persistence/persistence.module-definition.js +2 -2
- package/src/infrastructure-persistence/persistence.module-definition.js.map +1 -1
- package/src/infrastructure-persistence/persistence.module.js +34 -26
- package/src/infrastructure-persistence/persistence.module.js.map +1 -1
- package/src/infrastructure-persistence/repositories/typeorm-auth-account.repository.d.ts +14 -0
- package/src/infrastructure-persistence/repositories/typeorm-auth-account.repository.js +64 -0
- package/src/infrastructure-persistence/repositories/typeorm-auth-account.repository.js.map +1 -0
- package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.d.ts +6 -7
- package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.js +27 -17
- package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.js.map +1 -1
- package/src/presentation/controllers/auth.controller.d.ts +12 -7
- package/src/presentation/controllers/auth.controller.js +46 -26
- package/src/presentation/controllers/auth.controller.js.map +1 -1
- package/src/presentation/presentation.module.js +32 -3
- package/src/presentation/presentation.module.js.map +1 -1
- package/src/application/services/jwt-auth.service.d.ts +0 -11
- package/src/application/services/jwt-auth.service.js +0 -27
- package/src/application/services/jwt-auth.service.js.map +0 -1
- package/src/application/strategies/jwt-strategy.d.ts +0 -17
- package/src/application/strategies/jwt-strategy.js +0 -27
- package/src/application/strategies/jwt-strategy.js.map +0 -1
- package/src/infrastructure-engine/better-auth/better-auth-spike.harness.d.ts +0 -17
- package/src/infrastructure-engine/better-auth/better-auth-spike.harness.js +0 -32
- package/src/infrastructure-engine/better-auth/better-auth-spike.harness.js.map +0 -1
- package/src/infrastructure-engine/legacy-jwt-auth-engine.adapter.d.ts +0 -22
- package/src/infrastructure-engine/legacy-jwt-auth-engine.adapter.js.map +0 -1
- package/src/infrastructure-persistence/entities/invalidated-token.entity.js.map +0 -1
- package/src/infrastructure-persistence/repositories/auth-user.repository.js.map +0 -1
- /package/src/{infrastructure-persistence/repositories → application/ports}/auth-user.repository.js +0 -0
- /package/src/{infrastructure-persistence/entities → infrastructure-engine/better-auth/plugins/jwt}/invalidated-token.entity.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @anarchitects/auth-nest
|
|
2
2
|
|
|
3
|
-
NestJS services, controllers, and infrastructure for the Anarchitecture authentication domain. This package wires contract-driven DTOs from `@anarchitects/auth-ts`,
|
|
3
|
+
NestJS services, controllers, and infrastructure for the Anarchitecture authentication domain. This package wires contract-driven DTOs from `@anarchitects/auth-ts`, uses Better Auth as the canonical internal auth engine, keeps email/password always enabled, and layers repo-owned RBAC on top of Better Auth-backed user/session state.
|
|
4
|
+
|
|
5
|
+
Migration guidance for the Better Auth realignment lives in the [auth migration guide](../../../docs/guides/auth-migration.md).
|
|
4
6
|
|
|
5
7
|
## Developer + AI Agent Start Here
|
|
6
8
|
|
|
@@ -11,55 +13,82 @@ NestJS services, controllers, and infrastructure for the Anarchitecture authenti
|
|
|
11
13
|
|
|
12
14
|
## Features
|
|
13
15
|
|
|
14
|
-
- **Application layer** – `
|
|
15
|
-
- **Presentation layer** – `AuthController` exposing
|
|
16
|
-
- **Infrastructure persistence** –
|
|
16
|
+
- **Application layer** – Better Auth-backed `AuthService`, `BcryptHashService`, CASL-based `PoliciesService`, and `AbilityFactory` encapsulating business rules for sessions, passwords, and fine-grained access control.
|
|
17
|
+
- **Presentation layer** – `AuthController` exposing the package-owned core session-oriented auth lifecycle, `PoliciesGuard` and `@Policies()` decorator for route-level authorization, plus internal plugin controllers such as JWT when enabled.
|
|
18
|
+
- **Infrastructure persistence** – TypeORM entities and repositories for users, roles, permissions, and core Better Auth tables in the `auth` schema. Better Auth database operations are bridged internally through the published `@anarchitects/better-auth-typeorm-adapter`, while this repo keeps the Nest wrapper, entity registration, and migrations local. Plugin-specific tables and plugin-owned persistence such as JWT invalidation stay with their plugin modules.
|
|
17
19
|
- **Infrastructure mailer** – `AuthMailerModule` wrapper over shared `CommonMailerModule.forRoot(...)` provider wiring; `NodeMailerAdapter` is re-exported for compatibility.
|
|
18
|
-
- **Config** – Typed `authConfig` namespace using `@nestjs/config` with
|
|
20
|
+
- **Config** – Typed `authConfig` namespace using `@nestjs/config` with a Better Auth core config branch and typed plugin configuration.
|
|
19
21
|
|
|
20
22
|
## Installation
|
|
21
23
|
|
|
22
24
|
```bash
|
|
23
|
-
npm install @anarchitects/auth-nest @nestjs/common @nestjs/config @nestjs/core @nestjs/jwt @nestjs/
|
|
25
|
+
npm install @anarchitects/auth-nest @nestjs/common @nestjs/config @nestjs/core @nestjs/jwt @nestjs/platform-fastify @nestjs/typeorm typeorm
|
|
24
26
|
# or
|
|
25
|
-
yarn add @anarchitects/auth-nest @nestjs/common @nestjs/config @nestjs/core @nestjs/jwt @nestjs/
|
|
27
|
+
yarn add @anarchitects/auth-nest @nestjs/common @nestjs/config @nestjs/core @nestjs/jwt @nestjs/platform-fastify @nestjs/typeorm typeorm
|
|
26
28
|
```
|
|
27
29
|
|
|
28
30
|
Peer requirements:
|
|
29
31
|
|
|
30
|
-
- `@nestjs/common`, `@nestjs/core`, `@nestjs/jwt`, `@nestjs/typeorm`, `@nestjs/config
|
|
32
|
+
- `@nestjs/common`, `@nestjs/core`, `@nestjs/jwt`, `@nestjs/typeorm`, `@nestjs/config`
|
|
31
33
|
- `@nestjs/platform-fastify`, `typeorm`
|
|
32
34
|
|
|
33
|
-
The internal `@anarchitects/auth-ts` and `@anarchitects/common-nest-mailer` packages are installed transitively. Runtime utilities such as `@casl/ability`, `bcrypt`, and
|
|
35
|
+
The internal `@anarchitects/auth-ts` and `@anarchitects/common-nest-mailer` packages are installed transitively. The published community package `@anarchitects/better-auth-typeorm-adapter` is also installed transitively and used internally by `@anarchitects/auth-nest`; consumers do not need to wire it directly when using this package facade. Runtime utilities such as `@casl/ability`, `bcrypt`, `better-auth`, and `@better-auth/passkey` are direct dependencies of this package. Add `@nestjs-modules/mailer` only when your host app enables the shared/common mailer integration.
|
|
36
|
+
|
|
37
|
+
## Better Auth Adapter Boundary
|
|
38
|
+
|
|
39
|
+
`@anarchitects/auth-nest` now consumes the published `@anarchitects/better-auth-typeorm-adapter` package internally for Better Auth database composition.
|
|
40
|
+
|
|
41
|
+
- The community package provides only the framework-neutral Better Auth `database` adapter.
|
|
42
|
+
- This repo still owns the Nest wrapper, dependency injection, TypeORM entities, migrations, and plugin model registration.
|
|
43
|
+
- This internal swap does not add a new public Nest API or change the existing `AuthModule` / `AuthApplicationModule` integration surface.
|
|
44
|
+
|
|
45
|
+
Maintainers can validate the published npm artifact integration path with:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
yarn nx run auth-nest:test-published-adapter
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
That target boots `auth-nest` against ephemeral PostgreSQL and exercises the real published adapter package through the host repo's Nest integration path. It requires Docker or another supported local container runtime because the suite provisions PostgreSQL through `testcontainers`.
|
|
34
52
|
|
|
35
53
|
## Exports
|
|
36
54
|
|
|
37
|
-
| Import path | Contents
|
|
38
|
-
| ---------------------------------------------------- |
|
|
39
|
-
| `@anarchitects/auth-nest` | `AuthModule.forRoot(...)`, `AuthModule.forRootFromConfig(...)`, plus re-exports of layered entry points for convenience
|
|
40
|
-
| `@anarchitects/auth-nest/application` | `AuthApplicationModule`, `AuthService`, `
|
|
55
|
+
| Import path | Contents |
|
|
56
|
+
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
57
|
+
| `@anarchitects/auth-nest` | `AuthModule.forRoot(...)`, `AuthModule.forRootFromConfig(...)`, plus re-exports of layered entry points for convenience |
|
|
58
|
+
| `@anarchitects/auth-nest/application` | `AuthApplicationModule`, `AuthService`, `HashService`, `BcryptHashService`, `PoliciesService`, `AbilityFactory`, resource-authorization helpers/types |
|
|
41
59
|
| `@anarchitects/auth-nest/presentation` | `AuthPresentationModule`, `AuthController`, `PoliciesGuard`, `ResourceAuthorizationGuard`, `@Policies()`, `@AuthorizeResource()`, `@AuthorizedResource()`, `RoutePolicy` |
|
|
42
|
-
| `@anarchitects/auth-nest/infrastructure-persistence` | `AuthPersistenceModule`, `AuthUserRepository`,
|
|
43
|
-
| `@anarchitects/auth-nest/infrastructure-mailer` | `AuthMailerModule`, `NodeMailerAdapter`
|
|
44
|
-
| `@anarchitects/auth-nest/config` | `authConfig`, `AuthConfig` type, `InjectAuthConfig()`
|
|
60
|
+
| `@anarchitects/auth-nest/infrastructure-persistence` | `AuthPersistenceModule`, compatibility export for `AuthUserRepository`, and persistence module option types |
|
|
61
|
+
| `@anarchitects/auth-nest/infrastructure-mailer` | `AuthMailerModule`, `NodeMailerAdapter` |
|
|
62
|
+
| `@anarchitects/auth-nest/config` | `authConfig`, `AuthConfig` type, `InjectAuthConfig()` |
|
|
45
63
|
|
|
46
64
|
## Configuration
|
|
47
65
|
|
|
48
66
|
The library reads configuration through `@nestjs/config` using a namespaced `authConfig` registered under the key `auth`. Set the following environment variables to customise behaviour:
|
|
49
67
|
|
|
50
|
-
| Variable
|
|
51
|
-
|
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
| `
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
| Variable | Description | Default |
|
|
69
|
+
| ---------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------- |
|
|
70
|
+
| `AUTH_BETTER_AUTH_BASE_URL` | Better Auth base URL used for internal route generation. | `http://localhost:3000/api/auth` |
|
|
71
|
+
| `AUTH_BETTER_AUTH_SECRET` | Better Auth secret. **Must** be overridden in production. | `better-auth-secret-32-chars-minimum` |
|
|
72
|
+
| `AUTH_BETTER_AUTH_VERIFY_EMAIL_CALLBACK_URL` | App-facing callback URL embedded in verification emails. | `<base-url origin>/verify-email` |
|
|
73
|
+
| `AUTH_BETTER_AUTH_RESET_PASSWORD_CALLBACK_URL` | App-facing callback URL embedded in password reset emails. | `<base-url origin>/reset-password` |
|
|
74
|
+
| `AUTH_PLUGIN_JWT_ENABLED` | Enables the internal JWT plugin routes. | `false` |
|
|
75
|
+
| `AUTH_PLUGIN_JWT_SECRET` | Secret key used by the JWT plugin. **Must** be overridden when enabled. | `default_jwt_secret` |
|
|
76
|
+
| `AUTH_PLUGIN_JWT_EXPIRATION` | JWT plugin token lifetime (e.g. `3600s`, `15m`, `1d`). | `3600s` |
|
|
77
|
+
| `AUTH_PLUGIN_JWT_AUDIENCE` | Expected `aud` claim for JWT plugin tokens. | `your_audience` |
|
|
78
|
+
| `AUTH_PLUGIN_JWT_ISSUER` | Expected `iss` claim for JWT plugin tokens. | `your_issuer` |
|
|
79
|
+
| `AUTH_PLUGIN_PASSKEYS_ENABLED` | Enables the passkeys plugin. | `false` |
|
|
80
|
+
| `AUTH_PLUGIN_PASSKEY_RP_ID` | Passkey relying-party ID. | `localhost` |
|
|
81
|
+
| `AUTH_PLUGIN_PASSKEY_RP_NAME` | Passkey relying-party display name. | `Anarchitecture Auth` |
|
|
82
|
+
| `AUTH_PLUGIN_PASSKEY_ORIGIN` | Explicit passkey origin when needed. | unset |
|
|
83
|
+
| `AUTH_PLUGIN_SOCIAL_ENABLED` | Enables social auth plugins. | `false` |
|
|
84
|
+
| `AUTH_PLUGIN_SOCIAL_GITHUB_CLIENT_ID` | GitHub social sign-in client ID. | unset |
|
|
85
|
+
| `AUTH_PLUGIN_SOCIAL_GITHUB_CLIENT_SECRET` | GitHub social sign-in client secret. | unset |
|
|
86
|
+
| `AUTH_PLUGIN_OIDC_ENABLED` | Enables future OIDC plugin wiring. | `false` |
|
|
87
|
+
| `AUTH_ENCRYPTION_ALGORITHM` | Password hashing algorithm (`bcrypt`). | `bcrypt` |
|
|
88
|
+
| `AUTH_ENCRYPTION_KEY` | Symmetric key for additional encryption needs. **Must** be overridden. | `default_encryption_key` |
|
|
89
|
+
| `AUTH_MAILER_PROVIDER` | Domain mailer provider for `forRootFromConfig(...)` (`node` or `noop`). | `node` |
|
|
90
|
+
|
|
91
|
+
> **Security note:** The defaults for `AUTH_BETTER_AUTH_SECRET`, `AUTH_PLUGIN_JWT_SECRET`, and `AUTH_ENCRYPTION_KEY` are intentionally insecure placeholders. Always provide strong, unique values in any deployed environment.
|
|
63
92
|
|
|
64
93
|
### Injecting the config
|
|
65
94
|
|
|
@@ -71,7 +100,7 @@ export class MyService {
|
|
|
71
100
|
constructor(@InjectAuthConfig() private readonly config: AuthConfig) {}
|
|
72
101
|
|
|
73
102
|
someMethod() {
|
|
74
|
-
const secret = this.config.
|
|
103
|
+
const secret = this.config.betterAuth.secret;
|
|
75
104
|
}
|
|
76
105
|
}
|
|
77
106
|
```
|
|
@@ -109,14 +138,10 @@ import { authConfig } from '@anarchitects/auth-nest/config';
|
|
|
109
138
|
AuthModule.forRoot({
|
|
110
139
|
presentation: {
|
|
111
140
|
application: {
|
|
112
|
-
authStrategies: ['jwt'],
|
|
113
141
|
encryption: {
|
|
114
142
|
algorithm: 'bcrypt',
|
|
115
143
|
key: process.env.AUTH_ENCRYPTION_KEY!,
|
|
116
144
|
},
|
|
117
|
-
persistence: {
|
|
118
|
-
persistence: 'typeorm',
|
|
119
|
-
},
|
|
120
145
|
},
|
|
121
146
|
},
|
|
122
147
|
mailer: {
|
|
@@ -161,21 +186,17 @@ import { AuthMailerModule } from '@anarchitects/auth-nest/infrastructure-mailer'
|
|
|
161
186
|
}),
|
|
162
187
|
CommonMailerModule.forRootFromConfig(),
|
|
163
188
|
AuthApplicationModule.forRoot({
|
|
164
|
-
authStrategies: ['jwt'],
|
|
165
189
|
encryption: {
|
|
166
190
|
algorithm: 'bcrypt',
|
|
167
191
|
key: process.env.AUTH_ENCRYPTION_KEY!,
|
|
168
192
|
},
|
|
169
|
-
persistence: { persistence: 'typeorm' },
|
|
170
193
|
}),
|
|
171
194
|
AuthPresentationModule.forRoot({
|
|
172
195
|
application: {
|
|
173
|
-
authStrategies: ['jwt'],
|
|
174
196
|
encryption: {
|
|
175
197
|
algorithm: 'bcrypt',
|
|
176
198
|
key: process.env.AUTH_ENCRYPTION_KEY!,
|
|
177
199
|
},
|
|
178
|
-
persistence: { persistence: 'typeorm' },
|
|
179
200
|
},
|
|
180
201
|
}),
|
|
181
202
|
AuthMailerModule.forRoot({
|
|
@@ -188,6 +209,27 @@ export class AuthApiModule {}
|
|
|
188
209
|
|
|
189
210
|
Use layered composition when you need to replace or selectively compose infrastructure/application concerns.
|
|
190
211
|
|
|
212
|
+
### Optional JWT plugin
|
|
213
|
+
|
|
214
|
+
Core auth remains session-first. Only enable the JWT plugin when the host app explicitly needs token-based routes:
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
AuthModule.forRoot({
|
|
218
|
+
presentation: {
|
|
219
|
+
application: {
|
|
220
|
+
plugins: {
|
|
221
|
+
jwt: {
|
|
222
|
+
enabled: true,
|
|
223
|
+
secret: process.env.AUTH_PLUGIN_JWT_SECRET!,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
That mounts the plugin-owned `/auth/jwt/login`, `/auth/jwt/logout`, and `/auth/jwt/refresh` routes alongside the package-owned core session routes.
|
|
232
|
+
|
|
191
233
|
## Mailer Migration Note
|
|
192
234
|
|
|
193
235
|
`AuthMailerModule` is now adapter-only. It wraps shared `CommonMailerModule.forRoot(...)`
|
|
@@ -202,12 +244,12 @@ The shared mailer DI contract (`MailerPort`) and concrete `NodeMailerAdapter` no
|
|
|
202
244
|
|
|
203
245
|
```ts
|
|
204
246
|
import { Controller, Post, Body } from '@nestjs/common';
|
|
205
|
-
import {
|
|
247
|
+
import { AuthService } from '@anarchitects/auth-nest/application';
|
|
206
248
|
import { LoginRequestDTO } from '@anarchitects/auth-ts/dtos';
|
|
207
249
|
|
|
208
250
|
@Controller('auth')
|
|
209
251
|
export class AuthController {
|
|
210
|
-
constructor(private readonly authService:
|
|
252
|
+
constructor(private readonly authService: AuthService) {}
|
|
211
253
|
|
|
212
254
|
@Post('login')
|
|
213
255
|
login(@Body() dto: LoginRequestDTO) {
|
|
@@ -216,14 +258,6 @@ export class AuthController {
|
|
|
216
258
|
}
|
|
217
259
|
```
|
|
218
260
|
|
|
219
|
-
### Token invalidation
|
|
220
|
-
|
|
221
|
-
```ts
|
|
222
|
-
import { TypeormAuthUserRepository } from '@anarchitects/auth-nest/infrastructure-persistence';
|
|
223
|
-
|
|
224
|
-
await authUserRepository.invalidateTokens([hashedAccessToken, hashedRefreshToken], userId);
|
|
225
|
-
```
|
|
226
|
-
|
|
227
261
|
### Route-level authorization with policies
|
|
228
262
|
|
|
229
263
|
```ts
|
|
@@ -292,19 +326,26 @@ The library owns authorization orchestration. The host app still owns how domain
|
|
|
292
326
|
|
|
293
327
|
The `AuthController` exposes the following routes (all prefixed with `/auth`):
|
|
294
328
|
|
|
295
|
-
| Method | Path | Description
|
|
296
|
-
| ------- | ------------------------------- |
|
|
297
|
-
| `POST` | `/auth/register` | Register a new user
|
|
298
|
-
| `PATCH` | `/auth/activate` | Activate a user account
|
|
299
|
-
| `POST` | `/auth/login` | Log in and
|
|
300
|
-
| `POST` | `/auth/logout` | Log out and
|
|
301
|
-
| `PATCH` | `/auth/change-password/:userId` | Change password for a user
|
|
302
|
-
| `POST` | `/auth/forgot-password` | Request a password-reset email
|
|
303
|
-
| `POST` | `/auth/reset-password` | Reset password with token
|
|
304
|
-
| `POST` | `/auth/verify-email` | Verify an email address
|
|
305
|
-
| `PATCH` | `/auth/update-email/:userId` | Update email for a user
|
|
306
|
-
| `
|
|
307
|
-
|
|
329
|
+
| Method | Path | Description |
|
|
330
|
+
| ------- | ------------------------------- | ------------------------------------------ |
|
|
331
|
+
| `POST` | `/auth/register` | Register a new user |
|
|
332
|
+
| `PATCH` | `/auth/activate` | Activate a user account |
|
|
333
|
+
| `POST` | `/auth/login` | Log in and establish a Better Auth session |
|
|
334
|
+
| `POST` | `/auth/logout` | Log out and clear the Better Auth session |
|
|
335
|
+
| `PATCH` | `/auth/change-password/:userId` | Change password for a user |
|
|
336
|
+
| `POST` | `/auth/forgot-password` | Request a password-reset email |
|
|
337
|
+
| `POST` | `/auth/reset-password` | Reset password with token |
|
|
338
|
+
| `POST` | `/auth/verify-email` | Verify an email address |
|
|
339
|
+
| `PATCH` | `/auth/update-email/:userId` | Update email for a user |
|
|
340
|
+
| `GET` | `/auth/me` | Get logged-in user info and RBAC rules |
|
|
341
|
+
|
|
342
|
+
When the JWT plugin is enabled, these plugin-owned routes are also mounted:
|
|
343
|
+
|
|
344
|
+
| Method | Path | Description |
|
|
345
|
+
| ------ | ------------------- | ------------------------------ |
|
|
346
|
+
| `POST` | `/auth/jwt/login` | Log in and receive JWT tokens |
|
|
347
|
+
| `POST` | `/auth/jwt/logout` | Invalidate JWT plugin tokens |
|
|
348
|
+
| `POST` | `/auth/jwt/refresh` | Refresh JWT plugin token pairs |
|
|
308
349
|
|
|
309
350
|
## Nx scripts
|
|
310
351
|
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anarchitects/auth-nest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"@anarchitects/better-auth-typeorm-adapter": "0.1.0",
|
|
8
9
|
"@better-auth/passkey": "^1.5.6",
|
|
9
|
-
"@anarchitects/auth-ts": "^0.
|
|
10
|
-
"@anarchitects/common-nest-mailer": "^0.3.
|
|
10
|
+
"@anarchitects/auth-ts": "^0.6.0",
|
|
11
|
+
"@anarchitects/common-nest-mailer": "^0.3.2",
|
|
11
12
|
"@casl/ability": "^6.7.3",
|
|
13
|
+
"@opentelemetry/api": "^1.9.0",
|
|
12
14
|
"bcrypt": "^6.0.0",
|
|
13
15
|
"better-auth": "^1.5.6",
|
|
14
|
-
"passport-jwt": "^4.0.1",
|
|
15
16
|
"tslib": "^2.3.0",
|
|
16
17
|
"uuidv7": "^1.0.2"
|
|
17
18
|
},
|
|
@@ -20,7 +21,6 @@
|
|
|
20
21
|
"@nestjs/config": "^4.0.2",
|
|
21
22
|
"@nestjs/core": "^11.0.0",
|
|
22
23
|
"@nestjs/jwt": "^11.0.1",
|
|
23
|
-
"@nestjs/passport": "^11.0.5",
|
|
24
24
|
"@nestjs/platform-fastify": "^11.1.6",
|
|
25
25
|
"@nestjs/typeorm": "^11.0.0",
|
|
26
26
|
"typeorm": "^0.3.27"
|
|
@@ -56,6 +56,26 @@
|
|
|
56
56
|
"bugs": {
|
|
57
57
|
"url": "https://github.com/anarchitects/anarchitecture-bricks-3tier/issues"
|
|
58
58
|
},
|
|
59
|
+
"nx": {
|
|
60
|
+
"targets": {
|
|
61
|
+
"test-published-adapter": {
|
|
62
|
+
"executor": "nx:run-commands",
|
|
63
|
+
"dependsOn": [
|
|
64
|
+
"build"
|
|
65
|
+
],
|
|
66
|
+
"options": {
|
|
67
|
+
"command": "yarn node tools/testing/run-auth-nest-published-adapter-smoke.mjs"
|
|
68
|
+
},
|
|
69
|
+
"parallelism": false,
|
|
70
|
+
"cache": true,
|
|
71
|
+
"inputs": [
|
|
72
|
+
"default",
|
|
73
|
+
"^production",
|
|
74
|
+
"{workspaceRoot}/jest.preset.js"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
59
79
|
"exports": {
|
|
60
80
|
"./package.json": "./package.json",
|
|
61
81
|
".": {
|
|
@@ -7,26 +7,28 @@ const config_1 = require("@nestjs/config");
|
|
|
7
7
|
const jwt_1 = require("@nestjs/jwt");
|
|
8
8
|
const config_2 = require("../config");
|
|
9
9
|
const better_auth_auth_engine_adapter_1 = require("../infrastructure-engine/better-auth/better-auth-auth-engine.adapter");
|
|
10
|
-
const
|
|
10
|
+
const better_auth_jwt_plugin_service_1 = require("../infrastructure-engine/better-auth/plugins/jwt/better-auth-jwt-plugin.service");
|
|
11
|
+
const better_auth_jwt_typeorm_support_module_1 = require("../infrastructure-engine/better-auth/plugins/jwt/better-auth-jwt-typeorm-support.module");
|
|
12
|
+
const better_auth_passkeys_typeorm_support_module_1 = require("../infrastructure-engine/better-auth/plugins/passkeys/better-auth-passkeys-typeorm-support.module");
|
|
13
|
+
const better_auth_typeorm_adapter_persistence_adapter_1 = require("../infrastructure-engine/better-auth/better-auth-typeorm-adapter-persistence.adapter");
|
|
11
14
|
const infrastructure_persistence_1 = require("../infrastructure-persistence");
|
|
12
15
|
const application_module_definition_1 = require("./application.module-definition");
|
|
13
16
|
const ability_factory_1 = require("./factories/ability.factory");
|
|
14
17
|
const resource_authorization_tokens_1 = require("./resource-authorization.tokens");
|
|
15
18
|
const auth_engine_port_1 = require("./services/auth-engine.port");
|
|
19
|
+
const better_auth_database_port_1 = require("./services/better-auth-database.port");
|
|
16
20
|
const auth_orchestration_service_1 = require("./services/auth-orchestration.service");
|
|
17
21
|
const auth_service_1 = require("./services/auth.service");
|
|
18
22
|
const bcrypt_hash_service_1 = require("./services/bcrypt-hash.service");
|
|
19
23
|
const hash_service_1 = require("./services/hash.service");
|
|
20
|
-
const jwt_auth_service_1 = require("./services/jwt-auth.service");
|
|
21
24
|
const policies_service_1 = require("./services/policies.service");
|
|
22
|
-
const jwt_strategy_1 = require("./strategies/jwt-strategy");
|
|
23
25
|
let AuthApplicationModule = class AuthApplicationModule extends application_module_definition_1.ConfigurableModuleClass {
|
|
24
26
|
static forRoot(options = {}) {
|
|
25
27
|
const resolvedOptions = (0, config_2.resolveAuthApplicationModuleOptions)(options);
|
|
26
|
-
const {
|
|
28
|
+
const { encryption, resourceAuthorization } = resolvedOptions;
|
|
27
29
|
const imports = [
|
|
28
30
|
config_1.ConfigModule.forFeature(config_2.authConfig),
|
|
29
|
-
infrastructure_persistence_1.AuthPersistenceModule.forRoot(
|
|
31
|
+
infrastructure_persistence_1.AuthPersistenceModule.forRoot(),
|
|
30
32
|
];
|
|
31
33
|
const providers = [];
|
|
32
34
|
const exports = [];
|
|
@@ -49,45 +51,44 @@ let AuthApplicationModule = class AuthApplicationModule extends application_modu
|
|
|
49
51
|
default:
|
|
50
52
|
throw new Error(`Unsupported encryption algorithm: ${encryption.algorithm}`);
|
|
51
53
|
}
|
|
52
|
-
if (
|
|
54
|
+
if (resolvedOptions.plugins.jwt.enabled) {
|
|
55
|
+
imports.push(better_auth_jwt_typeorm_support_module_1.BetterAuthJwtTypeormSupportModule);
|
|
53
56
|
imports.push(jwt_1.JwtModule.registerAsync({
|
|
54
57
|
imports: [config_1.ConfigModule.forFeature(config_2.authConfig)],
|
|
55
58
|
inject: [config_2.authConfig.KEY],
|
|
56
|
-
useFactory: (
|
|
57
|
-
secret:
|
|
59
|
+
useFactory: (config) => ({
|
|
60
|
+
secret: config.plugins.jwt.secret,
|
|
58
61
|
signOptions: {
|
|
59
|
-
expiresIn:
|
|
60
|
-
audience:
|
|
61
|
-
issuer:
|
|
62
|
+
expiresIn: config.plugins.jwt.expiration,
|
|
63
|
+
audience: config.plugins.jwt.audience,
|
|
64
|
+
issuer: config.plugins.jwt.issuer,
|
|
62
65
|
},
|
|
63
66
|
}),
|
|
64
67
|
}));
|
|
65
|
-
providers.push(auth_orchestration_service_1.AuthOrchestrationService, jwt_strategy_1.JwtStrategy, {
|
|
66
|
-
provide: auth_service_1.AuthService,
|
|
67
|
-
useExisting: auth_orchestration_service_1.AuthOrchestrationService,
|
|
68
|
-
}, {
|
|
69
|
-
provide: jwt_auth_service_1.JwtAuthService,
|
|
70
|
-
useExisting: auth_orchestration_service_1.AuthOrchestrationService,
|
|
71
|
-
});
|
|
72
|
-
exports.push(auth_service_1.AuthService);
|
|
73
68
|
}
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
provide: auth_engine_port_1.AuthEnginePort,
|
|
77
|
-
useExisting: better_auth_auth_engine_adapter_1.BetterAuthAuthEngineAdapter,
|
|
78
|
-
});
|
|
69
|
+
if (resolvedOptions.plugins.passkeys.enabled) {
|
|
70
|
+
imports.push(better_auth_passkeys_typeorm_support_module_1.BetterAuthPasskeysTypeormSupportModule);
|
|
79
71
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
72
|
+
providers.push(auth_orchestration_service_1.AuthOrchestrationService, {
|
|
73
|
+
provide: auth_service_1.AuthService,
|
|
74
|
+
useExisting: auth_orchestration_service_1.AuthOrchestrationService,
|
|
75
|
+
}, better_auth_typeorm_adapter_persistence_adapter_1.BetterAuthTypeormDatabaseAdapter, {
|
|
76
|
+
provide: better_auth_database_port_1.BetterAuthDatabasePort,
|
|
77
|
+
useExisting: better_auth_typeorm_adapter_persistence_adapter_1.BetterAuthTypeormDatabaseAdapter,
|
|
78
|
+
}, better_auth_auth_engine_adapter_1.BetterAuthAuthEngineAdapter, {
|
|
79
|
+
provide: auth_engine_port_1.AuthEnginePort,
|
|
80
|
+
useExisting: better_auth_auth_engine_adapter_1.BetterAuthAuthEngineAdapter,
|
|
81
|
+
});
|
|
82
|
+
exports.push(auth_service_1.AuthService);
|
|
83
|
+
if (resolvedOptions.plugins.jwt.enabled) {
|
|
84
|
+
providers.push(better_auth_jwt_plugin_service_1.BetterAuthJwtPluginService);
|
|
85
85
|
}
|
|
86
|
+
const baseModule = super.forRoot(resolvedOptions);
|
|
86
87
|
return {
|
|
87
|
-
...
|
|
88
|
-
imports,
|
|
89
|
-
providers,
|
|
90
|
-
exports,
|
|
88
|
+
...baseModule,
|
|
89
|
+
imports: [...(baseModule.imports ?? []), ...imports],
|
|
90
|
+
providers: [...(baseModule.providers ?? []), ...providers],
|
|
91
|
+
exports: [...(baseModule.exports ?? []), ...exports],
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
static forRootFromConfig(overrides = {}) {
|
|
@@ -95,13 +96,37 @@ let AuthApplicationModule = class AuthApplicationModule extends application_modu
|
|
|
95
96
|
const moduleDefinition = this.forRoot({
|
|
96
97
|
...configOptions,
|
|
97
98
|
...overrides,
|
|
99
|
+
betterAuth: {
|
|
100
|
+
...configOptions.betterAuth,
|
|
101
|
+
...overrides.betterAuth,
|
|
102
|
+
callbackUrls: {
|
|
103
|
+
...configOptions.betterAuth?.callbackUrls,
|
|
104
|
+
...overrides.betterAuth?.callbackUrls,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
98
107
|
encryption: {
|
|
99
108
|
...configOptions.encryption,
|
|
100
109
|
...overrides.encryption,
|
|
101
110
|
},
|
|
102
|
-
|
|
103
|
-
...configOptions.
|
|
104
|
-
...overrides.
|
|
111
|
+
plugins: {
|
|
112
|
+
...configOptions.plugins,
|
|
113
|
+
...overrides.plugins,
|
|
114
|
+
jwt: {
|
|
115
|
+
...configOptions.plugins?.jwt,
|
|
116
|
+
...overrides.plugins?.jwt,
|
|
117
|
+
},
|
|
118
|
+
passkeys: {
|
|
119
|
+
...configOptions.plugins?.passkeys,
|
|
120
|
+
...overrides.plugins?.passkeys,
|
|
121
|
+
},
|
|
122
|
+
social: {
|
|
123
|
+
...configOptions.plugins?.social,
|
|
124
|
+
...overrides.plugins?.social,
|
|
125
|
+
},
|
|
126
|
+
oidc: {
|
|
127
|
+
...configOptions.plugins?.oidc,
|
|
128
|
+
...overrides.plugins?.oidc,
|
|
129
|
+
},
|
|
105
130
|
},
|
|
106
131
|
});
|
|
107
132
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.module.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/application.module.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"application.module.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/application.module.ts"],"names":[],"mappings":"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"}
|
|
@@ -6,7 +6,5 @@ export * from './resource-authorization.types';
|
|
|
6
6
|
export * from './services/auth.service';
|
|
7
7
|
export * from './services/bcrypt-hash.service';
|
|
8
8
|
export * from './services/hash.service';
|
|
9
|
-
export * from './services/jwt-auth.service';
|
|
10
9
|
export * from './services/policies.service';
|
|
11
10
|
export * from './services/resource-authorization';
|
|
12
|
-
export * from './strategies/jwt-strategy';
|
package/src/application/index.js
CHANGED
|
@@ -8,8 +8,6 @@ tslib_1.__exportStar(require("./resource-authorization.types"), exports);
|
|
|
8
8
|
tslib_1.__exportStar(require("./services/auth.service"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./services/bcrypt-hash.service"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./services/hash.service"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./services/jwt-auth.service"), exports);
|
|
12
11
|
tslib_1.__exportStar(require("./services/policies.service"), exports);
|
|
13
12
|
tslib_1.__exportStar(require("./services/resource-authorization"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./strategies/jwt-strategy"), exports);
|
|
15
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/index.ts"],"names":[],"mappings":";;;AACA,+DAAqC;AACrC,sEAA4C;AAC5C,0EAAgD;AAChD,yEAA+C;AAC/C,kEAAwC;AACxC,yEAA+C;AAC/C,kEAAwC;AACxC,sEAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/index.ts"],"names":[],"mappings":";;;AACA,+DAAqC;AACrC,sEAA4C;AAC5C,0EAAgD;AAChD,yEAA+C;AAC/C,kEAAwC;AACxC,yEAA+C;AAC/C,kEAAwC;AACxC,sEAA4C;AAC5C,4EAAkD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type CredentialAccount = {
|
|
2
|
+
id: string;
|
|
3
|
+
userId: string;
|
|
4
|
+
accountId: string;
|
|
5
|
+
providerId: 'credential';
|
|
6
|
+
password: string | null;
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
updatedAt: Date;
|
|
9
|
+
};
|
|
10
|
+
export declare abstract class AuthAccountRepository {
|
|
11
|
+
abstract findCredentialAccountByUserId(userId: string): Promise<CredentialAccount | null>;
|
|
12
|
+
abstract upsertCredentialAccount(input: {
|
|
13
|
+
userId: string;
|
|
14
|
+
passwordHash: string;
|
|
15
|
+
createdAt?: Date;
|
|
16
|
+
updatedAt?: Date;
|
|
17
|
+
}): Promise<CredentialAccount>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthAccountRepository = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
let AuthAccountRepository = class AuthAccountRepository {
|
|
7
|
+
};
|
|
8
|
+
exports.AuthAccountRepository = AuthAccountRepository;
|
|
9
|
+
exports.AuthAccountRepository = AuthAccountRepository = tslib_1.__decorate([
|
|
10
|
+
(0, common_1.Injectable)()
|
|
11
|
+
], AuthAccountRepository);
|
|
12
|
+
//# sourceMappingURL=auth-account.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-account.repository.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/ports/auth-account.repository.ts"],"names":[],"mappings":";;;;AAAA,2CAA4C;AAarC,IAAe,qBAAqB,GAApC,MAAe,qBAAqB;CAW1C,CAAA;AAXqB,sDAAqB;gCAArB,qBAAqB;IAD1C,IAAA,mBAAU,GAAE;GACS,qBAAqB,CAW1C"}
|
package/src/{infrastructure-persistence/repositories → application/ports}/auth-user.repository.d.ts
RENAMED
|
@@ -2,9 +2,8 @@ import { User } from '@anarchitects/auth-ts/models';
|
|
|
2
2
|
export declare abstract class AuthUserRepository {
|
|
3
3
|
abstract find(conditions: unknown): Promise<User[]>;
|
|
4
4
|
abstract findOne(conditions: unknown): Promise<User>;
|
|
5
|
+
abstract ensureRole(userId: string, roleName: string): Promise<void>;
|
|
5
6
|
abstract create(user: Partial<User>): Promise<User>;
|
|
6
7
|
abstract update(user: Partial<User>): Promise<User>;
|
|
7
8
|
abstract delete(userId: string): Promise<User>;
|
|
8
|
-
abstract invalidateTokens(tokens: string[], userId: string | null): Promise<void>;
|
|
9
|
-
abstract isTokenInvalidated(tokenId: string): Promise<boolean>;
|
|
10
9
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-user.repository.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/ports/auth-user.repository.ts"],"names":[],"mappings":";;;;AAAA,2CAA4C;AAIrC,IAAe,kBAAkB,GAAjC,MAAe,kBAAkB;CAOvC,CAAA;AAPqB,gDAAkB;6BAAlB,kBAAkB;IADvC,IAAA,mBAAU,GAAE;GACS,kBAAkB,CAOvC"}
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export type AuthorizableResource = Record<string, unknown>;
|
|
3
|
-
export type ResourceAuthorizationLoaderInput = {
|
|
4
|
-
user: User;
|
|
5
|
-
resourceId: string;
|
|
6
|
-
};
|
|
7
|
-
export type ResourceAuthorizationLoader<TResource extends AuthorizableResource = AuthorizableResource> = (input: ResourceAuthorizationLoaderInput) => Promise<TResource | null> | TResource | null;
|
|
8
|
-
export type ResourceAuthorizationLoaders = Record<string, ResourceAuthorizationLoader>;
|
|
9
|
-
export type ResourceAuthorizationOptions = {
|
|
10
|
-
loaders?: ResourceAuthorizationLoaders;
|
|
11
|
-
};
|
|
12
|
-
export type ResourceAuthorizationRoute = {
|
|
13
|
-
action: Action;
|
|
14
|
-
subject: Subject;
|
|
15
|
-
idParam: string;
|
|
16
|
-
};
|
|
1
|
+
export type { AuthorizableResource, ResourceAuthorizationLoader, ResourceAuthorizationLoaderInput, ResourceAuthorizationLoaders, ResourceAuthorizationOptions, ResourceAuthorizationRoute, } from '../config/resource-authorization.types';
|