Snapshot for
@system-core/core0.10.x. Current docs live at /.
NestJS
Import from @system-core/core/integrations/nestjs.
Use this when NestJS owns the HTTP shell and system-core owns the auth or CMS runtime behind it.
Install
npm install @system-core/core @nestjs/common
npm install zod bcryptjs jsonwebtoken nodemailerAdd @prisma/client only when you are also using the package-owned Prisma schema.
Basic Setup
Register SystemCoreModule with your HTTP adapter and either your own AuthDeps or a runtime created elsewhere.
import { Module } from '@nestjs/common'
import { SystemCoreModule, nestjsAdapter } from '@system-core/core/integrations/nestjs'
import type { AuthDeps } from '@system-core/core'
const authDeps: AuthDeps = {
users: { /* ... */ },
roles: { /* ... */ },
permissions: { /* ... */ },
rolePermissions: { /* ... */ },
userPermissions: { /* ... */ },
invites: { /* ... */ },
passwordResets: { /* ... */ },
emailVerifications: { /* ... */ },
sessions: { /* ... */ }
}
@Module({
imports: [
SystemCoreModule.forRoot({
http: nestjsAdapter,
auth: authDeps
})
]
})
export class AppModule {}SystemCoreModule.forRoot() now returns a real NestJS DynamicModule, so it can be imported directly in AppModule without the old startup crash.
Guards
Use guards with a package-owned auth runtime, not the raw adapter bag. For custom schemas, build that runtime from your AuthDeps.
import { Controller, Get, Post, UseGuards } from '@nestjs/common'
import { createAuthSystem, createConfig } from '@system-core/core'
import { createAuthGuard, createPermissionGuard } from '@system-core/core/integrations/nestjs'
const authSystem = createAuthSystem(authDeps, createConfig())
const AuthGuard = createAuthGuard(authSystem)
const CanPublishGuard = createPermissionGuard(
'cms:publish',
(userId, permission) => authSystem.authorization.hasEffectivePermission(userId, permission)
)
@Controller('content')
export class ContentController {
@Get('me')
@UseGuards(AuthGuard)
me() {
return { ok: true }
}
@Post('publish')
@UseGuards(AuthGuard, CanPublishGuard)
publish() {
return { published: true }
}
}createAuthGuard(authSystem) verifies the bearer access token through auth.sessions.verifyToken() and stores the resolved session payload on request.user.
DI Injection
Everything you pass into forRoot() is registered under SYSTEM_CORE_TOKEN.
import { Controller, Get, Inject, Injectable } from '@nestjs/common'
import type { AuthDeps } from '@system-core/core'
import { SYSTEM_CORE_TOKEN } from '@system-core/core/integrations/nestjs'
import type { SystemCoreProviders } from '@system-core/core/integrations/nestjs'
@Injectable()
export class AuthAdapterService {
constructor(
@Inject(SYSTEM_CORE_TOKEN) private readonly core: SystemCoreProviders
) {}
get authDeps(): AuthDeps {
return this.core.auth as AuthDeps
}
}
@Controller('health')
export class HealthController {
constructor(private readonly authAdapter: AuthAdapterService) {}
@Get()
check() {
return { authConfigured: !!this.authAdapter.authDeps.sessions }
}
}Custom Prisma Schemas
If your Prisma schema does not expose the package-owned model names, do not call createPrismaDeps() against it. Build AuthDeps manually and pass it through SystemCoreModule.forRoot({ auth }) or createSystem({ auth }) instead.
Direct Adapter Usage
import { Controller, Get } from '@nestjs/common'
import { getNestjsEvent, nestjsAdapter } from '@system-core/core/integrations/nestjs'
@Controller('echo')
export class EchoController {
@Get()
echo(ctx: any) {
const event = getNestjsEvent(ctx)
const method = nestjsAdapter.getMethod(event)
const url = nestjsAdapter.getRequestURL(event)
return { method, pathname: url.pathname }
}
}API Reference
| Export | Kind | Description |
|---|---|---|
nestjsAdapter / httpAdapter | HttpAdapter | NestJS request/response adapter |
getNestjsEvent(ctx) | function | Converts a Nest ExecutionContext into the adapter event shape |
createAuthGuard(authSystem) | function | Factory returning a bearer-token guard |
createPermissionGuard(permission, checkFn) | function | Factory returning a permission guard |
SystemCoreModule | class | Decorated NestJS module class with .forRoot(config) |
SYSTEM_CORE_TOKEN | const | DI token for whatever you registered via forRoot() |
SystemCoreProviders | type | Provider bag registered by the module |