Skip to content

Authentication System for NestJS SaaS

Every auth pattern your SaaS needs — JWT with refresh token rotation, Google OAuth, two-factor authentication, magic links, email verification, and account security. All production-tested and ready to customize.

Building authentication from scratch takes 2-4 weeks and is the #1 source of security vulnerabilities in SaaS applications. The Cloudrix SaaS Starter Kit gives you a battle-tested auth system built on NestJS, Passport.js, and bcrypt, with a clean Angular frontend. Every flow — registration, login, password reset, email verification — is fully implemented with proper error handling and security best practices.

JWT + Refresh Tokens

15-minute access tokens with 7-day refresh token rotation. Passwords are hashed with bcrypt (12 salt rounds). Tokens are stored securely and rotated on every refresh to prevent token replay attacks. The frontend handles silent refresh automatically.

Google OAuth 2.0

One-click Google login via Passport.js. Auto-links to existing accounts by email. New users are automatically created with their Google profile data. No extra configuration needed — just add your Google Client ID and Secret.

Two-Factor Authentication (2FA)

TOTP-based 2FA compatible with Google Authenticator, Authy, and 1Password. QR code setup flow with 8 backup codes generated on activation. 2FA is enforced at every login when enabled, with a clean UI for code entry.

Magic Links

Passwordless login via email with 10-minute expiry and single-use tokens. Built on Resend for reliable email delivery. Users click a link in their email and are instantly logged in — no password to remember, no friction.

Account Security

Account lockout after 5 failed login attempts with automatic unlock after 15 minutes. Password reset via email with 1-hour expiring tokens. Rate limiting on all auth endpoints (5 req/min for login, 3 req/min for password reset).

Email Verification

24-hour verification tokens sent on registration. Beautiful, responsive email templates via Resend. Unverified accounts can log in but see a reminder banner. Re-send verification with rate limiting to prevent abuse.

How It Works in Code

The auth module is built on NestJS guards and Passport.js strategies. Here's how a protected endpoint looks:

// Protect any endpoint with a single decorator
@UseGuards(JwtAuthGuard)
@Get('profile')
getProfile(@CurrentUser() user: User) {
  return { id: user.id, email: user.email };
}

// Require 2FA verification
@UseGuards(JwtAuthGuard, TwoFactorGuard)
@Post('transfer')
transferFunds(@Body() dto: TransferDto) {
  // Only runs if user passed 2FA
}

What's Included

JWT access + refresh token rotation
Google OAuth 2.0 with auto-linking
TOTP-based 2FA with backup codes
Magic link passwordless login
Email verification with Resend
Password reset with expiring tokens
Account lockout after failed attempts
Rate limiting on auth endpoints
Bcrypt password hashing (12 rounds)
Passport.js strategy architecture
Angular auth guard + interceptor
Silent token refresh on frontend
Session management UI
CORS and Helmet security headers
Get SaaS Starter Pro — $249

One-time purchase. 14-day money-back guarantee.