From 5b3b9d0da2bf38c40086a0b75c3784ef93e938de Mon Sep 17 00:00:00 2001 From: fabiodalez-dev Date: Thu, 25 Jun 2026 00:32:36 +0200 Subject: [PATCH] fix(mobile): align register payload with backend + gate Profile actions on feature flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two findings from the mobile review: - RegisterRequest (and AuthRepository.register) only sent nome/cognome/email/ password, but the backend AuthController requires telefono, indirizzo, password_confirm and privacy_acceptance — it 422s (privacy_required / missing_fields) otherwise. Add the missing fields (snake_case via @SerialName) so registration matches the contract. - ProfileScreen always showed the Notifications and "Message the library" actions regardless of the instance's `notifications` / `messages` feature flags. Gate them on InstanceFeatures so the app reflects what the library actually exposes via the Mobile API. Verified: ./gradlew :app:compileDebugKotlin BUILD SUCCESSFUL. --- .../java/com/pinakes/app/data/model/Models.kt | 9 +++++++- .../app/data/repository/AuthRepository.kt | 21 +++++++++++++++++-- .../app/ui/screens/profile/ProfileScreen.kt | 11 ++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/pinakes/app/data/model/Models.kt b/app/src/main/java/com/pinakes/app/data/model/Models.kt index d055a00..e88e74d 100644 --- a/app/src/main/java/com/pinakes/app/data/model/Models.kt +++ b/app/src/main/java/com/pinakes/app/data/model/Models.kt @@ -74,7 +74,14 @@ data class RegisterRequest( val nome: String, val cognome: String, val email: String, - val password: String, // min 8 + // Backend (AuthController) requires these too and 422s without them: + // privacy must be accepted, phone + address are mandatory, and the password + // must be confirmed (8-72 chars, upper+lower+digit). + val telefono: String, + val indirizzo: String, + val password: String, + @SerialName("password_confirm") val passwordConfirm: String, + @SerialName("privacy_acceptance") val privacyAcceptance: Boolean, ) @Serializable diff --git a/app/src/main/java/com/pinakes/app/data/repository/AuthRepository.kt b/app/src/main/java/com/pinakes/app/data/repository/AuthRepository.kt index c432948..6b3bec2 100644 --- a/app/src/main/java/com/pinakes/app/data/repository/AuthRepository.kt +++ b/app/src/main/java/com/pinakes/app/data/repository/AuthRepository.kt @@ -88,9 +88,26 @@ class AuthRepository( } } - suspend fun register(nome: String, cognome: String, email: String, password: String): ApiResult { + suspend fun register( + nome: String, + cognome: String, + email: String, + telefono: String, + indirizzo: String, + password: String, + passwordConfirm: String, + privacyAcceptance: Boolean, + ): ApiResult { val api = network.api() - return apiCall { api.register(RegisterRequest(nome.trim(), cognome.trim(), email.trim(), password)) } + return apiCall { + api.register( + RegisterRequest( + nome.trim(), cognome.trim(), email.trim(), + telefono.trim(), indirizzo.trim(), + password, passwordConfirm, privacyAcceptance, + ) + ) + } } suspend fun forgotPassword(email: String): ApiResult { diff --git a/app/src/main/java/com/pinakes/app/ui/screens/profile/ProfileScreen.kt b/app/src/main/java/com/pinakes/app/ui/screens/profile/ProfileScreen.kt index 1762717..ca368b8 100644 --- a/app/src/main/java/com/pinakes/app/ui/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/com/pinakes/app/ui/screens/profile/ProfileScreen.kt @@ -146,6 +146,9 @@ private fun ProfileContent( onOpenNotifications: () -> Unit, onOpenContact: () -> Unit, ) { + // Instance feature flags — gate the messaging/notifications actions so the + // app reflects what the library actually exposes via the Mobile API. + val features by LocalServices.current.features.features.collectAsStateWithLifecycle() Column( Modifier .fillMaxSize() @@ -192,8 +195,12 @@ private fun ProfileContent( // Actions ActionRow(Icons.Outlined.Edit, stringResource(R.string.profile_action_edit), onClick = onEdit) ActionRow(Icons.Outlined.Lock, stringResource(R.string.profile_action_change_password), onClick = onChangePassword) - ActionRow(Icons.Outlined.Notifications, stringResource(R.string.profile_action_notifications), onClick = onOpenNotifications) - ActionRow(Icons.Outlined.ChatBubbleOutline, stringResource(R.string.profile_action_message_library), onClick = onOpenContact) + if (features.notifications) { + ActionRow(Icons.Outlined.Notifications, stringResource(R.string.profile_action_notifications), onClick = onOpenNotifications) + } + if (features.messages) { + ActionRow(Icons.Outlined.ChatBubbleOutline, stringResource(R.string.profile_action_message_library), onClick = onOpenContact) + } Spacer(Modifier.height(Spacing.xl))