{
  "name": "BARIN ALP - Auth Login",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "auth/login",
        "options": {
          "allowedOrigins": "*"
        }
      },
      "id": "webhook-login",
      "name": "Webhook Login",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "1Mvg9vxzp7LyYwNor0i8o8LvqYiF0ID4WD3Af58zkVTo",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Users",
          "mode": "list"
        }
      },
      "id": "sheets-get-users",
      "name": "Get Users",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.4,
      "position": [
        470,
        300
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "condition-user-found",
              "leftValue": "={{ $json.username }}",
              "rightValue": "={{ $('Webhook Login').item.json.body.username }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "filter-user",
      "name": "Filter User",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2,
      "position": [
        690,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "condition-pin",
              "leftValue": "={{ $json.pin }}",
              "rightValue": "={{ $('Webhook Login').item.json.body.password }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "check-pin",
      "name": "Check PIN",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        910,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ {\n  \"success\": true,\n  \"token\": \"token-\" + $json.id + \"-\" + Date.now(),\n  \"user\": {\n    \"id\": $json.id,\n    \"username\": $json.username,\n    \"name\": $json.name,\n    \"role\": $json.role\n  }\n} }}",
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Access-Control-Allow-Origin",
                "value": "*"
              }
            ]
          }
        }
      },
      "id": "respond-success",
      "name": "Success Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1130,
        200
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { \"success\": false, \"message\": \"\u0413\u0440\u0435\u0448\u0435\u043d PIN \u043a\u043e\u0434\" } }}",
        "options": {
          "responseCode": 401,
          "responseHeaders": {
            "entries": [
              {
                "name": "Access-Control-Allow-Origin",
                "value": "*"
              }
            ]
          }
        }
      },
      "id": "respond-error",
      "name": "Error Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1130,
        400
      ]
    }
  ],
  "connections": {
    "Webhook Login": {
      "main": [
        [
          {
            "node": "Get Users",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Users": {
      "main": [
        [
          {
            "node": "Filter User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter User": {
      "main": [
        [
          {
            "node": "Check PIN",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check PIN": {
      "main": [
        [
          {
            "node": "Success Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}