MCPcopy
hub / github.com/cloudflare/vibesdk / register

Method register

worker/api/controllers/auth/controller.ts:46–95  ·  view source on GitHub ↗

* Register a new user * POST /api/auth/register

(request: Request, env: Env, _ctx: ExecutionContext, _routeContext: RouteContext)

Source from the content-addressed store, hash-verified

44 * POST /api/auth/register
45 */
46 static async register(request: Request, env: Env, _ctx: ExecutionContext, _routeContext: RouteContext): Promise<Response> {
47 try {
48 // Check if OAuth providers are configured - if yes, block email/password registration
49 if (AuthController.hasOAuthProviders(env)) {
50 return AuthController.createErrorResponse(
51 'Email/password registration is not available when OAuth providers are configured. Please use OAuth login instead.',
52 403
53 );
54 }
55
56 const bodyResult = await AuthController.parseJsonBody(request);
57 if (!bodyResult.success) {
58 return bodyResult.response!;
59 }
60
61 const validatedData = registerSchema.parse(bodyResult.data);
62
63 if (env.ALLOWED_EMAIL && validatedData.email !== env.ALLOWED_EMAIL) {
64 return AuthController.createErrorResponse(
65 'Email Whitelisting is enabled. Please use the allowed email to register.',
66 403
67 );
68 }
69
70 const authService = new AuthService(env);
71 const result = await authService.register(validatedData, request);
72
73 const response = AuthController.createSuccessResponse(
74 formatAuthResponse(result.user, result.sessionId, result.expiresAt)
75 );
76
77 setSecureAuthCookies(response, {
78 accessToken: result.accessToken,
79 accessTokenExpiry: SessionService.config.sessionTTL
80 });
81
82 // Rotate CSRF token on successful registration if configured
83 if (CsrfService.defaults.rotateOnAuth) {
84 CsrfService.rotateToken(response);
85 }
86
87 return response;
88 } catch (error) {
89 if (error instanceof SecurityError) {
90 return AuthController.createErrorResponse(error.message, error.statusCode);
91 }
92
93 return AuthController.handleError(error, 'register user');
94 }
95 }
96
97 /**
98 * Login with email and password

Callers

nothing calls this directly

Calls 8

registerMethod · 0.95
formatAuthResponseFunction · 0.90
setSecureAuthCookiesFunction · 0.90
hasOAuthProvidersMethod · 0.80
parseJsonBodyMethod · 0.80
parseMethod · 0.80
rotateTokenMethod · 0.80
handleErrorMethod · 0.80

Tested by

no test coverage detected