Skip to main content

Sign-up (Self-service Registration)

Overview

The registration module lets new customers sign themselves up without waiting for an admin to create an account. The flow is straightforward: the user fills in the sign-up form, the system creates an organization and a user, sends a verification email, and once the user clicks the link they can start using the platform. A realtime duplicate-email check is also exposed for the web form.

Every route in this module is @Public(), since no token exists yet at this stage.

Business Flow

  1. As the user types an email address, cms-web calls GET /api/auth/check-email?email=... to report immediately whether the address is available or already registered.
  2. POST /api/auth/register submits the sign-up data — email, password, organization name, and so on.
    • The password is hashed with bcrypt in hash.go.
    • Rows are created in organization and user, with the default customer role attached.
    • A random verification token is generated via crypto/rand and hex-encoded.
    • The endpoint responds with 201.
  3. The verification email is sent through the shared Mailer in internal/mail, which reads the same MAIL_SMTP_* environment variables the original NestJS nodemailer transport used, so the resulting emails are identical.
  4. The user clicks the link, which hits GET /api/auth/verify-email?token=.... The user's status flips to verified and they can log in.
  5. From here the user enters the normal flow: log in, choose a LINE OA, and start using the CMS.

Key Files & Functions

The code lives in internal/modules/registration/, comprising controller.go, service.go, dto.go, and hash.go.

MethodRouteHandlerGuard
POST/api/auth/registerct.registerpublic (returns 201)
GET/api/auth/verify-emailct.verifyEmailpublic, takes the token query param
GET/api/auth/check-emailct.checkEmailpublic, takes the email query param

RegisterRoutes(public, _, d) — this module never touches the authed group.

Connections to Other Services

  • Permission — none required; every route is public.
  • Tablesorganization, user, system_role (for the default role), and password_history.
  • Mailerinternal/mail/mail.go, configured from MAIL_SMTP_HOST, MAIL_SMTP_PORT, MAIL_SMTP_USER, MAIL_SMTP_PASS, MAIL_SMTP_FROM_NAME, and MAIL_SMTP_FROM_EMAILADDRESS.
  • Known deviation — the NestJS version built its own nodemailer transport in the constructor, while the Go version uses the shared Mailer. Sending behaviour is unchanged because both read the same environment variables.
  • Follow-on reading — Login & JWT, and User Management.