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
- 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. POST /api/auth/registersubmits the sign-up data — email, password, organization name, and so on.- The password is hashed with bcrypt in
hash.go. - Rows are created in
organizationanduser, with the default customer role attached. - A random verification token is generated via
crypto/randand hex-encoded. - The endpoint responds with 201.
- The password is hashed with bcrypt in
- The verification email is sent through the shared Mailer in
internal/mail, which reads the sameMAIL_SMTP_*environment variables the original NestJS nodemailer transport used, so the resulting emails are identical. - 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. - 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.
| Method | Route | Handler | Guard |
|---|---|---|---|
| POST | /api/auth/register | ct.register | public (returns 201) |
| GET | /api/auth/verify-email | ct.verifyEmail | public, takes the token query param |
| GET | /api/auth/check-email | ct.checkEmail | public, 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.
- Tables —
organization,user,system_role(for the default role), andpassword_history. - Mailer —
internal/mail/mail.go, configured fromMAIL_SMTP_HOST,MAIL_SMTP_PORT,MAIL_SMTP_USER,MAIL_SMTP_PASS,MAIL_SMTP_FROM_NAME, andMAIL_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.