RabbinatixDocs
Sign inGet started

Example

Build a registration flow

A new person signs up with an email, a password and a display name. The auth service checks the email format and the password policy, refuses an email that is already taken, and stores the new user.

You will build

  • The POST /api/v1/register API, connected to the web app
  • A users.insert operation next to the lookup
  • 2 pieces of logic: the sign-up form and the register logic
  • The User registration flow with test data, 4 test cases and 2 requirements, all passing

System map

  • Web AppAuth ServicePOST /api/v1/register
  • Auth ServiceUsers DBusers.findByIdentifier (query)
  • Auth ServiceUsers DBusers.insert (insert)

This guide reuses Web App, Auth Service, Users DB and users.findByIdentifier from the login example. Starting fresh? Do the login steps 1 and 4 first.

In a hurry? The free Email & password registration flow in the Store builds all of this for you.Open it in the Store

Part 1: Declare the register API

  1. 1.

    Open Auth Service. On APIs, click Add an API.

  2. 2.

    Under Basics:

    This endpoint is…
    Provided
    Method
    POST
    Path
    /api/v1/register
    Summary
    Create an account
    Lifecycle
    To do
  3. 3.

    Type the Request body. The ? makes the display name optional.

    email: string
    password: string
    displayName?: string
  4. 4.

    Change the 200 response’s status to 201 and type its body:

    id: integer
    email: string
  5. 5.

    Click +400 and type its body:

    error: string
    field: string
  6. 6.

    Click +409 and type its body, then click Create endpoint.

    error: string

Part 2: Connect the web app to the API

  1. 1.

    Open Web App → … → Add a dependency…. Consumer Web App, provider Auth Service.

  2. 2.

    Tick POST /api/v1/register and click Connect 1 API.

Check: The Web App → Auth Service line stays green and now carries two APIs.

Part 3: Add the insert operation

  1. 1.

    Open Users DB → Resources → Operation.

  2. 2.

    Fill in and click Save. Untick may return nothing.

    Name
    users.insert
    Type
    insert
    Query / description
    INSERT INTO users (email, password_hash, display_name) VALUES (:email, :passwordHash, :displayName)
    Input fields
    email: string passwordHash: string displayName?: string
    Output fields
    id: integer

Part 4: Build the sign-up form logic on the web app

  1. 1.

    Open Web App → Logic → + Logic. Choose Event / UI action.

    Event name
    Submit registration form
    Name
    Submit registration form
  2. 2.

    Inputs:

    email
    Email
    password
    Text
    displayName
    Text
  3. 3.

    Return values:

    success
    Yes / No
    userId
    Whole number
    message
    Text
  4. 4.

    Click Create and open. In Details, make displayName, userId and message nullable (string | null, integer | null) and click the eye next to password to lock it.

  5. 5.

    Add Make Object (label Build request) with these fields, connected from On Event:

    email: string
    password: string
    displayName?: string
  6. 6.

    Add Call Contract (label Call register) with API POST /api/v1/register. Connect the On Event arrow into it and object into body.

  7. 7.

    From 201: Return with success = true, message = null, userId from Get Property id on the call’s body.

  8. 8.

    From 400 and from 409: a Return each, success = false, userId = null, message from Get Property error on body.

  9. 9.

    From Other: Return with success = false, userId = null, message = Something went wrong.

  10. 10.

    Tick Key step on Call register and the success Return.

Check: The Problems tab is empty.

Part 5: Build the register logic on the auth service

  1. 1.

    Open Auth Service → APIs. On POST /api/v1/register, click + Logic.

  2. 2.

    Add Break Object with these fields, fed from On Request body:

    email: string
    password: string
    displayName?: string
  3. 3.

    Add Validate Email (field email) on email, and a Branch Email valid? on its valid.

  4. 4.

    From False: Return Response 400. Body: Make Object error: string + field: string, with error from the validation message and field = email.

  5. 5.

    From True: Validate Password on password. In Details: Min length 8, Require a digit on. Then a Branch Password strong enough?.

  6. 6.

    From its False: Return Response 400, body error from the message, field = password.

  7. 7.

    From its True: Query Database users.findByIdentifier (label Find existing user) with email.

  8. 8.

    From Found: Return Response 409, body Make Object error = An account with this email already exists.

  9. 9.

    From Not found: Database Insert (label Create user), Operation users.insert. Connect email and displayName from Break Object, and passwordHash from a Format hash:{password}.

  10. 10.

    Then Return Response 201. Body: Make Object id: integer + email: string, with id from Get Property id on the insert result and email from Break Object.

  11. 11.

    Tick Key step on Find existing user, Create user and the 201 answer.

Check: The Problems tab is empty.

Part 6: Create the flow

  1. 1.

    Flows → New flow, then Create flow:

    Name
    User registration
    Where does the flow start?
    Existing logic
    (the list)
    Web App · Submit registration form (event)
    Criticality
    Important
  2. 2.

    Click the flow’s name → Secret inputs (masked in runs) password, passwordHash → save.

Check: Lanes Web App → Auth Service → Users DB → Auth Service → Web App.

Part 7: Add test data

  1. 1.

    Test data → New test data → users.findByIdentifier. Name Email already registered, WHEN email == "taken@example.com", THEN RETURN:

    { "id": 7, "email": "taken@example.com", "passwordHash": "hash:x", "status": "active" }
  2. 2.

    Any other email must come back empty. If you built the login, Unknown identifier already does that. If not, add it: WHEN email = * (any), THEN RETURN null.

  3. 3.

    New test data → users.insert. Name Created user, WHEN email = * (any), THEN RETURN:

    { "id": 2 }
  4. 4.

    Expected results → New expected result for User registration. Account created: success equals true, userId exists, message is null.

  5. 5.

    Already registered: success equals false, message contains "already exists".

  6. 6.

    Invalid email: success equals false, message contains "valid email".

  7. 7.

    Weak password: success equals false, message contains "password must".

Part 8: Write the test cases

  1. 1.

    Open User registration → Test → Manage… → New, once per row.

  2. 2.

    New account: expect Account created. Under Database & queue expectations, add users.insert: email equals "new@example.com" and passwordHash equals "hash:Secret123".

    { "email": "new@example.com", "password": "Secret123", "displayName": "Nia" }
  3. 3.

    Email already in use: expect Already registered.

    { "email": "taken@example.com", "password": "Secret123", "displayName": "Nia" }
  4. 4.

    Invalid email: expect Invalid email.

    { "email": "not-an-email", "password": "Secret123", "displayName": "Nia" }
  5. 5.

    Weak password: expect Weak password.

    { "email": "new@example.com", "password": "short", "displayName": "Nia" }

Part 9: Link the requirements

  1. 1.

    Requirements → New requirement: An email can only be registered once. Flow User registration, test case Email already in use.

  2. 2.

    New requirement: Passwords must meet the password policy. Test case Weak password.

Part 10: Run it and verify the code

  1. 1.

    Open the flow → Test → Run all. Fix any failing step and run again.

  2. 2.

    Open … and pick Check the generated code.

Check: Every test case is green, and both requirements read Verified (passing).