feat(auth): registration mode on ConnectPage (PUBLIC_ENABLE_REGISTRATION)
Add a login/register toggle to ConnectPage backed by a new useRegisterMutation (register -> /auth/me, mirroring login). The toggle is shown only when REGISTRATION_ENABLED, resolved with the same precedence as the API base URL: runtime window.__APP_CONFIG__ > PUBLIC_ENABLE_REGISTRATION env > default true. The prod runtime-config script injects the runtime flag. The backend's ALLOW_REGISTRATION stays the real authority; this only gates the UI. EN/RU strings added. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { api } from '../index';
|
||||
import { toUser, type RawUser } from '../mappers';
|
||||
import type { AuthTokens, LoginRequest, LoginResponse, User } from '../types';
|
||||
import type {
|
||||
AuthTokens,
|
||||
LoginRequest,
|
||||
LoginResponse,
|
||||
RegisterRequest,
|
||||
User,
|
||||
} from '../types';
|
||||
|
||||
/**
|
||||
* Auth seam over the backend's wire format: tokens-only login + a separate
|
||||
@@ -48,6 +54,29 @@ export const authApi = api.injectEndpoints({
|
||||
return { data: { user, tokens } };
|
||||
},
|
||||
}),
|
||||
// Sign-up mirrors login: POST /auth/register returns a token pair (the
|
||||
// backend logs the new account straight in), then GET /auth/me resolves the
|
||||
// user — so the UI gets the same unified { user, tokens } as login.
|
||||
register: build.mutation<LoginResponse, RegisterRequest>({
|
||||
async queryFn(body, _api, _extra, baseQuery) {
|
||||
const tokenRes = await baseQuery({
|
||||
url: '/auth/register',
|
||||
method: 'POST',
|
||||
body,
|
||||
});
|
||||
if (tokenRes.error) return { error: tokenRes.error };
|
||||
const tokens = toTokens(tokenRes.data as RawTokenResponse);
|
||||
|
||||
const meRes = await baseQuery({
|
||||
url: '/auth/me',
|
||||
headers: { Authorization: `Bearer ${tokens.accessToken}` },
|
||||
});
|
||||
if (meRes.error) return { error: meRes.error };
|
||||
const user = toUser(meRes.data as RawUser);
|
||||
|
||||
return { data: { user, tokens } };
|
||||
},
|
||||
}),
|
||||
logout: build.mutation<void, { refreshToken: string }>({
|
||||
query: ({ refreshToken }) => ({
|
||||
url: '/auth/logout',
|
||||
@@ -74,6 +103,7 @@ export const authApi = api.injectEndpoints({
|
||||
|
||||
export const {
|
||||
useLoginMutation,
|
||||
useRegisterMutation,
|
||||
useLogoutMutation,
|
||||
useRefreshTokenMutation,
|
||||
useMeQuery,
|
||||
|
||||
Reference in New Issue
Block a user