This n8n workflow provides a comprehensive solution for user authentication and management, leveraging Airtable as the backend database. It includes flows for user sign-up and login, aswell as the sample crud operations retrieving user details, and updating user information.
Youtube Video of me explaining the flow: https://www.youtube.com/watch?v=gKcGfyq3dPM
How it Works
User Sign-Up Flow
- Receives POST request: A webhook listens for POST requests containing new user details (email, first name, last name, password).
- Checks for existing email: The workflow queries Airtable to see if the submitted email already exists.
- Handles email in use: If the email is found, it responds with
{"response": "email in use"}
.
- Creates new user: If the email is unique, the password is SHA256 hashed (Base64 encoded), and the user's information (including the hashed password) is stored in Airtable. A successful response of
{"response": "success"}
is then sent.
User Login Flow
- Receives POST request: A webhook listens for POST requests with user email and password for login.
- Verifies user existence: It checks Airtable for a user with the provided email. If no user is found, it responds with a failure message (
"wrong email"
).
- Compares passwords: If a user is found, the submitted password is hashed (SHA256, Base64 encoded) and compared with the stored hashed password in Airtable.
- Responds with JWT or error: If passwords match, a JWT token containing the user's ID and email is issued. If they don't match, a
"wrong password"
response is sent.
Flows for a Logged-In User
These flows require a JWT-authenticated request.
-
Get User Details:
- Webhook (GET): Receives a JWT-authenticated request.
- Airtable (Read): Fetches the current user’s record using the
jwtPayload.id
.
- Set Node ("Specify Current Details"): Maps fields like "First Name," "Last Name," "Email," and "Date" from Airtable to a standard output format.
-
Update User Details:
- Webhook (POST): Receives updated user data (email, name, password).
- Airtable (Upsert): Updates the record matching
jwtPayload.id
using the submitted fields.
- Set Node ("Specify New Details"): Outputs the updated data in a standard format.
Set Up Steps (Approx. 5 Minutes)
Step 1: Set up your Airtable Base and Table
You'll need an Airtable Base and a table to store your user data. Ensure your table has at least the following columns:
- Email (Single Line Text)
- First Name (Single Line Text)
- Last Name (Single Line Text)
- Password (Single Line Text - this will store the hashed password)
- Date (Date - optional, for user sign-up date)
Step 2: Obtain an Airtable Personal Access Token
- Go to the Airtable website and log in to your account.
- Navigate to your personal access token page (usually found under your developer settings or by searching for "personal access tokens").
- Click "Create new token."
- Give your token a name (e.g., "n8n User Management").
- Grant necessary permissions:
- Scope:
data.records:read
, data.records:write
for the specific base you will be using.
- Base: Select the Airtable base where your user management table resides.
- Generate the token and copy it immediately. You won't be able to see it again. Store it securely.
Step 3: Create a JWT Auth Credential in n8n
- In your n8n instance, go to "Credentials" (usually found in the left-hand sidebar).
- Click "New Credential" and search for "JWT Auth".
- Give the credential a name (e.g., "UserAuthJWT").
- For the "Signing Secret," enter a strong, random string of characters. This secret will be used to sign and verify your JWT tokens. Keep this secret highly confidential.
- Save the credential.
Customization Options
This workflow is designed to be highly adaptable:
- Database Integration: Easily switch from Airtable to other databases like PostgreSQL, MySQL, MongoDB, or even Google Sheets by replacing the Airtable nodes with the appropriate database nodes in n8n.
- Authentication Methods: Extend the authentication to include multi-factor authentication (MFA), social logins (Google, Facebook), or integrate with existing identity providers (IdP) by adding additional nodes.
- User Profile Fields: Add or remove user profile fields (e.g., phone number, address, user roles) by adjusting the Airtable table columns and the Set nodes in the workflow.
- Notification System: Integrate notification systems (e.g., email, SMS) for events like new user sign-ups, password resets, or account changes.
- Admin Panel: Build an admin panel using n8n to manage users directly, including functionalities for adding, deleting, or updating user records, and resetting passwords.
This workflow provides a solid foundation for building robust user management systems, adaptable to a wide range of applications and security requirements.
Need Assistance or Customization?
Do you have specific integrations in mind, or are you looking to add more user management features to this workflow?
If you need help setting this up, or want to adapt it for a unique use case, don't hesitate to reach out! You can contact me directly at [email protected]. I'd be glad to assist you.