Agent skill
nestjs-bcryptjs-setup
Install, repair, and verify bcryptjs hashing in NestJS with ConfigModule-based SALT_ROUNDS validation, a reusable hash/verify EncryptionService, and a global EncryptionModule export. Use when users ask to add or fix password hashing, credential verification, auth secret hashing, login compare flow, or reusable bcrypt utilities.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/nestjs-bcryptjs-setup
SKILL.md
NestJS bcryptjs Setup
Use this workflow to add reusable one-way secret hashing with bcryptjs.
Prerequisites
- NestJS backend with
AppModuleandsrc - Node.js 20+ for modern Nest projects
@nestjs/configavailable soSALT_ROUNDScan be read from environment
Preflight checks
- Confirm target is a NestJS backend root containing
package.json,src/main.ts, andsrc/app.module.ts. - Confirm package manager from lockfile:
package-lock.json-> usenpmpnpm-lock.yaml-> usepnpmyarn.lock-> useyarn
- If required files are missing, stop and report the exact missing path before editing.
Install dependencies
If @nestjs/config is missing, install it first.
npm install @nestjs/config
Install bcrypt packages from project root:
npm install bcryptjs
npm install -D @types/bcryptjs
Equivalent commands may be used for pnpm or yarn, but keep dependency intent identical.
Configure SALT_ROUNDS
Add SALT_ROUNDS to .env:
- Production:
10-12 - Tests/local fast feedback:
4-8
Example:
SALT_ROUNDS=10
If not already present, wire global config in AppModule:
ConfigModule.forRoot({ isGlobal: true })
If ConfigModule.forRoot({ isGlobal: true }) already exists, do not duplicate it.
Add EncryptionService
Implement EncryptionService from reference.md with these rules:
- Inject
ConfigService. - Parse and validate
SALT_ROUNDSonce in the constructor. - Expose
hash(plain: string): Promise<string>. - Expose
verify(plain: string, hashed: string): Promise<boolean>. - Use only one-way terms (
hashandverify), not encrypt/decrypt names. - Throw clear startup errors when
SALT_ROUNDSis missing or out of accepted range.
Add EncryptionModule
Create a global module from reference.md that:
- imports
ConfigModule - provides
EncryptionService - exports
EncryptionService
Register EncryptionModule in AppModule.imports.
Optional env helper
Use addEncryptionEnvVariables from reference.md if the project generates .env or .env.example files programmatically.
Suggested file layout
src/libs/encryption/encryption.service.tssrc/libs/encryption/encryption.module.tssrc/libs/encryption/encryption.utils.ts(optional)src/libs/encryption/index.ts
Verification
- Run backend checks from project root:
npm run build
npm run test
- Verify hashing flow:
verify(plain, await hash(plain))returnstrue.verify('wrong', await hash('correct'))returnsfalse.
- Verify config guardrails:
- App boots with valid
SALT_ROUNDS. - Missing or invalid
SALT_ROUNDSfails fast with a clear startup error.
- App boots with valid
- If any check fails, report exact failing command or assertion and stop before claiming completion.
Checklist
- Confirm NestJS project root and package manager
- Install
bcryptjsand@types/bcryptjs - Ensure
ConfigModule.forRoot({ isGlobal: true })is configured - Add
SALT_ROUNDSto.env - Add
EncryptionServiceandEncryptionModulefrom reference.md - Import
EncryptionModuleinAppModule - Run build and tests, then verify hash/compare flow end to end
Additional resources
- Full code snippets: reference.md
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?