Secure User Authentication System using Webhooks and PostgreSQL - n8n Workflow

Build a secure user authentication backend with this powerful n8n workflow. Includes signup, signin, and password reset using PostgreSQL's pgcrypto for bcrypt hashing.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Developers needing a secure backend for prototypes or MVPs.

  • System architects integrating identity management into custom applications.

  • Users looking for advanced examples of PostgreSQL and custom logic within an n8n workflow.

  • Anyone seeking robust n8n templates for handling sensitive user data.

Overview

Implementing a secure authentication system traditionally requires complex server-side coding. This n8n workflow simplifies the process by leveraging the power of PostgreSQL's built-in cryptographic functions (pgcrypto) and the flexible routing capabilities of the n8n node ecosystem.

This robust n8n workflow centralizes user management into one endpoint. When an external application (like a front-end UI or mobile app) calls the webhook, the system securely handles user creation (signup with bcrypt hashing), credential verification (signin), and automatic password generation (forgot password). It serves as an excellent example of using an n8n trigger for external API interaction while maintaining high security standards. This particular n8n workflow drastically cuts down development time for backend authentication services.

How it Works

The automation begins with a dedicated n8n trigger:


  1. Webhook Trigger: The process starts when a client sends a POST request to the /auth endpoint. The request body must contain path (specifying 'signup', 'signin', or 'forgot'), email, and optionally, password or name.

  2. Router Node: A crucial n8n node, the Router, analyzes the path value from the incoming request. It directs the execution flow to the appropriate PostgreSQL logic branch.

  3. Signup Path: If path is 'signup', the flow hits the Signup PostgreSQL n8n node. This node executes a SQL query using crypt() and gen_salt('bf') to securely hash the user's password using bcrypt before insertion.

  4. Login Path: If path is 'signin', the Login PostgreSQL n8n node queries the user by email (case-insensitive) and uses PostgreSQL's crypt() function to compare the provided password against the stored hash. The result, including a boolean isPasswordMatch, passes to the Check Login n8n node.

  5. Validation: The Check Login IF n8n node verifies if both a user ID was found and the password matched. It routes the result to either a success or failure response.

  6. Forgot Password Path: If path is 'forgot', the Reset Password n8n node generates a new 8-character random password, updates the user record, and returns the new plain-text password for immediate user display or for emailing.

  7. Response: All successful actions, validation failures, or database errors conclude by sending a standardized JSON response (status, message, data) back via the Respond n8n node.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided n8n workflow JSON and import it into your n8n instance.

  2. Database Setup: This n8n workflow requires a PostgreSQL or Supabase database with a users table. Ensure the uuid-ossp and pgcrypto extensions are enabled in your database.

* Create the required table structure:
CREATE TABLE users (
id uuid PRIMARY KEY DEFAULT uuidgeneratev4(),
fullname text NOT NULL,
email text UNIQUE NOT NULL,
password
hash text NOT NULL,
created_at timestamptz DEFAULT now()
);

  1. Credentials: Set up PostgreSQL credentials within n8n. In the Signup, Login, and Reset Password n8n node configurations, assign your PostgreSQL credential set (e.g., 'Project: Edubot').

  2. Activation: Activate the n8n workflow. The Webhook n8n trigger endpoint will now be live and ready to receive authentication requests.

Node Details

Webhook (n8n trigger):
Function: Serves as the single API endpoint (/auth) for all authentication actions.
Key Configuration: Method set to POST; Response Mode set to 'Response Node'.
Router (Switch n8n node):
Function: Routes the execution based on the path variable ($json["path"]), directing traffic to 'signup', 'signin', or 'forgot'.
Key Configuration: Uses three outputs corresponding to the three required paths.
Signup (PostgreSQL n8n node):
Function: Inserts a new user record. Uses crypt('{{$json["password"]}}', gen_salt('bf')) for secure password hashing.
Login (PostgreSQL n8n node):
Function: Retrieves user data and compares the incoming password against the stored hash using a secure SQL query that returns isPasswordMatch.
Check Login (IF n8n node):
Function: Core flow control logic. Validates the results of the Login query (checks if user exists and password matches).
Key Configuration: Condition checks id existence AND isPasswordMatch equals true.
Reset Password (PostgreSQL n8n node):
Function: Generates a random 8-character string and updates the user's password hash in the database.
Respond (n8n node):
* Function: Finalizes the request by sending the status, message, and data back to the client that initiated the n8n trigger.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by

Featured*