Skip to content

Cấu hình

1. Biến môi trường

Nguồn: EnvironmentKeys trong @nx/core/src/common/environments.ts. Service đọc qua applicationEnvironment.get<T>(key).

Core runtime

TênKiểuMặc địnhBắt buộcMô tả
APP_ENV_PORTnumber3000Cổng HTTP listen
APP_ENV_HOSTstring0.0.0.0Địa chỉ bind
APP_ENV_BASE_PATHstring/v1/api/identityTiền tố route
APP_ENV_NODE_IDnumberSnowflake worker ID — phải là 1 cho identity
APP_ENV_LOG_LEVELinfo|debug|warn|errorinfo
APP_ENV_NODE_ENVstringdevelopmentdotenv-flow loader
RUN_MODEmigrate|servermigrate chuyển sang entry migration

Database

TênKiểuMặc địnhBắt buộcMô tả
APP_ENV_DB_URLstringURL kết nối PostgreSQL
APP_ENV_DB_POOL_MAXnumber10

Redis (OTP + auth cache)

TênKiểuMặc địnhBắt buộcMô tả
APP_ENV_REDIS_HOSTstringOTP yêu cầu Redis; auth cache là tuỳ chọn
APP_ENV_REDIS_PORTnumber6379
APP_ENV_REDIS_PASSWORDstring
APP_ENV_REDIS_DBnumber0

JWKS / Ký token

TênKiểuMặc địnhBắt buộcMô tả
APP_ENV_APPLICATION_SECRETstringDùng bởi CryptoUtility cho AES-256-GCM (mã hoá mail/SMS configs)
APP_ENV_JWKS_PRIVATE_KEY (hoặc k8s secret)PEMPrivate key ES256 để ký JWT
APP_ENV_JWKS_PUBLIC_KEY (hoặc k8s secret)PEMPublic key tương ứng được publish tại /jw-certs

Tên env-var chính xác phụ thuộc vào cấu hình @nx/core/IssuerApplication. Tham khảo JWT helper của @nx/core để biết tên chuẩn.

Mail (SMTP)

TênKiểuMặc địnhMô tả
APP_ENV_SMTP_HOSTstringsmtp.gmail.comMáy chủ SMTP
APP_ENV_SMTP_PORTnumber587
APP_ENV_SMTP_USERNAMEstring
APP_ENV_SMTP_PASSWORDstring

WebSocket

TênKiểuMặc địnhMô tả
APP_ENV_WEBSOCKET_REDIS_MODESINGLE|CLUSTERSINGLEChế độ single-instance vs Redis Cluster cho WS emitter

2. Feature Flags

FlagLưu trữMặc địnhMô tả
OTP bật theo channelBản ghi ConfigurationenabledBật/tắt email vs phone OTP
Mail templates theo merchantConfiguration theo merchantIdglobalOverride template hệ thống

3. Dữ liệu Seed

7 process migration trong src/migrations/processes/. Chạy khi bootstrap.

FilePhạm viGhi chú
identity-0001-seed-roles.ts6 system rolesSUPER_ADMIN, ADMIN, OPERATOR, OWNER, EMPLOYEE, CUSTOMER (bất biến)
identity-0002-seed-users.tsUser admin/test mặc địnhTiện cho dev
identity-0003-seed-table-configurations.tsMặc định OTP/mail/password trong ConfigurationOTP TTLs, giới hạn số lần thử, lockout
identity-0004-seed-mail-configurations.tsMail templates (verify-email, forgot-password, welcome, password-changed × en/vi)8 bản ghi
identity-0005-seed-permissions.tsToàn bộ IdentityPermissionsPermission CRUD theo controller; alwaysRun=true
identity-0006-seed-sms-configurations.tsCấu hình provider VN Pay SMSđã mã hoá
identity-0007-seed-sms-templates.tsSMS templates (phone-auth, add-phone × en/vi)4 bản ghi

4. Cách dùng bảng Configuration

Identity đọc/ghi:

Loại ConfigurationGroupMã hoáĐọc bởi
Mail validation defaults (CODE_LENGTH, CODE_EXPIRY, v.v.)MAIL_VALIDATIONhằng số MailValidationFields
Mail templatesMAILMailTemplateService
OTP policyOTPBaseOTPBasedMFAService
SMS templatesSMSSmsTemplateService
SMS provider credentialsSMS_PARAMETER_CONFIGUREAES-256-GCMMQSMSComponent

Templates có thể override theo từng merchant qua partial unique index (group, code, principalId, principalType).

5. Thứ tự Boot

6. Trang liên quan

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.