workflows.fit
Back to n8n workflows
n8n templateFreeBy Luka Zivkovic

Host your own JWT authentication system with Data Tables and token management

Description A production-ready authentication workflow implementing secure user registration, login, token verification, and refresh token mechanisms. Perfect for adding authentication to any application without needi...

DevelopmentCore NodesUtilityCryptoSetData TableCode
Loading interactive preview...

Template notes

Description A production-ready authentication workflow implementing secure user registration, login, token verification, and refresh token mechanisms. Perfect for adding authentication to any application without needing a separate auth service.

Get started with [n8n](https://n8n.partnerlinks.io/ds9podzjls6d) now!

What it does This template provides a complete authentication backend using n8n workflows and Data Tables: - User Registration: Creates accounts with secure password hashing (SHA-512 + unique salts) - Login System: Generates access tokens (15 min) and refresh tokens (7 days) using JWT - Token Verification: Validates access tokens for protected endpoints - Token Refresh: Issues new access tokens without requiring re-login - Security Features: HMAC-SHA256 signatures, hashed refresh tokens in database, protection against rainbow table attacks Why use this template - No external services: Everything runs in n8n - no Auth0, Firebase, or third-party dependencies - Production-ready security: Industry-standard JWT implementation with proper token lifecycle management - Easy integration: Simple REST API endpoints that work with any frontend framework - Fully customizable: Adjust token lifespans, add custom user fields, implement your own business logic - Well-documented: Extensive inline notes explain every security decision and implementation detail How to set up Prerequisites - n8n instance (cloud or self-hosted) - n8n Data Tables feature enabled Setup Steps 1. Create Data Tables: - users table: id, email, username, passwordhash, refreshtoken - refreshtokens table: id, userid, tokenhash, expiresat 2. Generate Secret Keys: Run this command to generate a random secret:

node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

Generate two different secrets for ACCESSSECRET and REFRESHSECRET 3. Configure Secrets: - Update the three "SET ACCESS AND REFRESH SECRET" nodes with your generated keys - Or migrate to n8n Variables for better security (instructions in workflow notes) 4. Connect Data Tables: - Open each Data Table node - Select your created tables from the dropdown 5. Activate Workflow: - Save and activate the workflow - Note your webhook URLs API Endpoints Register: POST /webhook/register-user Request body:

{ "email": "user@example.com", "username": "username", "password": "password123" }

Login: POST /webhook/login Request body:

{ "email": "user@example.com", "password": "password123" }