认证面板(注册/登录/忘记密码)

高级

这是一个Engineering领域的自动化工作流,包含 16 个节点。主要使用 If、Switch、Webhook、Postgres、RespondToWebhook 等节点。 使用PostgreSQL和Webhooks创建完整的用户认证系统

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • PostgreSQL 数据库连接信息
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "cIhoaw0VJGihOHmy",
  "meta": {
    "instanceId": "deff2e7875268ae3fbe0cda0c3aa28feebb743b5a609a8cf33e4b05565651d9c",
    "templateCredsSetupCompleted": true
  },
  "name": "认证面板(注册/登录/忘记密码)",
  "tags": [],
  "nodes": [
    {
      "id": "e430c384-eec7-4c18-a105-ae8d4d5216bc",
      "name": "概述",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        176,
        1568
      ],
      "parameters": {
        "color": 5,
        "width": 600,
        "height": 640,
        "content": "## 概述:认证"
      },
      "typeVersion": 1
    },
    {
      "id": "a81f1cc2-4d7b-4d71-a103-667f43724c17",
      "name": "Webhook 文档",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        816,
        1568
      ],
      "parameters": {
        "color": 5,
        "width": 624,
        "height": 464,
        "content": "## Webhook:入口点"
      },
      "typeVersion": 1
    },
    {
      "id": "ee0f4193-74e8-4df4-ba1e-09950cc38dfe",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1104,
        1856
      ],
      "webhookId": "d670d0e6-ac14-4b3f-b556-593969c1c8f2",
      "parameters": {
        "path": "auth",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "1a42c7bc-b3ff-4495-8207-cffe9c2edc70",
      "name": "Switch 文档",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1456,
        1568
      ],
      "parameters": {
        "color": 5,
        "width": 528,
        "height": 472,
        "content": "## Switch:路由操作"
      },
      "typeVersion": 1
    },
    {
      "id": "e4b6610a-5fcc-4dea-82d7-b8388ba39cdc",
      "name": "路由器",
      "type": "n8n-nodes-base.switch",
      "position": [
        1648,
        1824
      ],
      "parameters": {
        "rules": {
          "rules": [
            {
              "output": 1,
              "value2": "signup"
            },
            {
              "output": 2,
              "value2": "signin"
            },
            {
              "output": 3,
              "value2": "forgot"
            }
          ]
        },
        "value1": "={{$json[\"path\"]}}",
        "dataType": "string",
        "fallbackOutput": 0
      },
      "typeVersion": 1
    },
    {
      "id": "68549d4c-294a-4a74-a849-ee87814334fb",
      "name": "注册文档",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2000,
        1568
      ],
      "parameters": {
        "color": 6,
        "width": 580,
        "height": 472,
        "content": "## PostgreSQL:注册"
      },
      "typeVersion": 1
    },
    {
      "id": "2dd10f62-a7af-4ed3-bbf9-acb3ab00a5c7",
      "name": "注册",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2352,
        1888
      ],
      "parameters": {
        "query": "INSERT INTO users (full_name, email, password_hash)\nVALUES (\n  '{{$json[\"name\"]}}',\n  '{{$json[\"email\"]}}',\n  crypt('{{$json[\"password\"]}}', gen_salt('bf'))\n)\nRETURNING id, full_name, email, created_at;\n",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "id": "RCxqFMerFYoFK91z",
          "name": "Project: Edubot"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "2ded10d4-9715-4a06-991a-b5224039f5aa",
      "name": "登录文档",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        2096
      ],
      "parameters": {
        "color": 6,
        "width": 532,
        "height": 600,
        "content": "## PostgreSQL:登录"
      },
      "typeVersion": 1
    },
    {
      "id": "7cb04861-2a0b-4298-b050-f6fd232439e1",
      "name": "登录",
      "type": "n8n-nodes-base.postgres",
      "position": [
        864,
        2528
      ],
      "parameters": {
        "query": "SELECT\n  id,\n  full_name,\n  email,\n  (password_hash = crypt('{{$json[\"password\"]}}', password_hash)) AS \"isPasswordMatch\"\nFROM users\nWHERE LOWER(email) = LOWER('{{$json[\"email\"]}}');\n",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "id": "RCxqFMerFYoFK91z",
          "name": "Project: Edubot"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "d189c3bf-9e95-4666-b205-50734ee47821",
      "name": "IF 文档",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1392,
        2096
      ],
      "parameters": {
        "color": 6,
        "width": 400,
        "height": 600,
        "content": "## IF:验证登录"
      },
      "typeVersion": 1
    },
    {
      "id": "b154b3cb-d21e-4451-b526-fca72281d0ab",
      "name": "检查登录",
      "type": "n8n-nodes-base.if",
      "position": [
        1504,
        2528
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "41d2a73b-ece5-4043-894a-ab8bf12e55b3",
              "operator": {
                "type": "boolean",
                "operation": "equal"
              },
              "leftValue": "={{ $json[\"id\"] !== undefined && $json[\"isPasswordMatch\"] === true }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f7b96eac-f2a1-489c-92e5-10ab62244003",
      "name": "忘记密码文档",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1808,
        2096
      ],
      "parameters": {
        "color": 6,
        "width": 580,
        "height": 608,
        "content": "## PostgreSQL:忘记密码"
      },
      "typeVersion": 1
    },
    {
      "id": "360ce51c-db91-46ec-841e-518abb068712",
      "name": "重置密码",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2144,
        2416
      ],
      "parameters": {
        "query": "WITH new_pass AS (\n  SELECT substring(md5(random()::text) from 1 for 8) AS plain_password\n)\nUPDATE users\nSET password_hash = crypt(new_pass.plain_password, gen_salt('bf'))\nFROM new_pass\nWHERE LOWER(email) = LOWER('{{$json[\"email\"]}}')\nRETURNING email, new_pass.plain_password AS newPassword;\n",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "id": "RCxqFMerFYoFK91z",
          "name": "Project: Edubot"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "0a9bf2d6-a7ff-47e4-874f-b6ad0274199c",
      "name": "响应文档",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2432,
        2096
      ],
      "parameters": {
        "color": 5,
        "width": 688,
        "height": 600,
        "content": "## 响应:发送响应"
      },
      "typeVersion": 1
    },
    {
      "id": "cef94eb3-936a-496a-a950-90c8708ec56a",
      "name": "响应",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        2848,
        2544
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.4
    },
    {
      "id": "b5d535cc-a1a0-4674-b56f-4f9f2fd6a08d",
      "name": "数据库设置",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        176,
        2240
      ],
      "parameters": {
        "color": 5,
        "width": 600,
        "height": 480,
        "content": "## 数据库设置"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {
    "Webhook": [
      {
        "json": {
          "path": "forgot",
          "email": "ali.raza@example.com"
        }
      }
    ]
  },
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e51c5384-1056-4f65-a0f1-187b68971e0e",
  "connections": {
    "Login": {
      "main": [
        [
          {
            "node": "Check Login",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Router": {
      "main": [
        [],
        [
          {
            "node": "Signup",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Login",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reset Password",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Signup": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Login": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reset Password": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

这是一个高级难度的工作流,适用于Engineering等场景。适合高级用户,包含 16+ 个节点的复杂工作流

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量16
分类1
节点类型6
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

外部链接
在 n8n.io 上查看 →

分享此工作流