Add delete account feature to mobile app
- DELETE /api/auth/account/ API call in AuthApi + APILayer - authProvider field on User model for email vs social auth detection - DeleteAccountDialog with password (email) or "type DELETE" (social) confirmation - Red "Delete Account" card on ProfileScreen - Navigation wired in App.kt (clears data, returns to login) - 10 i18n strings in strings.xml - ViewModel unit tests for delete account state
This commit is contained in:
@@ -1333,6 +1333,18 @@ object APILayer {
|
||||
return result
|
||||
}
|
||||
|
||||
suspend fun deleteAccount(password: String? = null, confirmation: String? = null): ApiResult<Unit> {
|
||||
val token = getToken() ?: return ApiResult.Error("Not authenticated", 401)
|
||||
val result = authApi.deleteAccount(token, DeleteAccountRequest(password = password, confirmation = confirmation))
|
||||
|
||||
// Clear DataManager on successful deletion
|
||||
if (result is ApiResult.Success) {
|
||||
DataManager.clear()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// ==================== Notification Operations ====================
|
||||
|
||||
suspend fun registerDevice(request: DeviceRegistrationRequest): ApiResult<DeviceRegistrationResponse> {
|
||||
|
||||
@@ -228,6 +228,26 @@ class AuthApi(private val client: HttpClient = ApiClient.httpClient) {
|
||||
}
|
||||
}
|
||||
|
||||
// Delete Account
|
||||
suspend fun deleteAccount(token: String, request: DeleteAccountRequest): ApiResult<Unit> {
|
||||
return try {
|
||||
val response = client.delete("$baseUrl/auth/account/") {
|
||||
header("Authorization", "Token $token")
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(request)
|
||||
}
|
||||
|
||||
if (response.status.isSuccess()) {
|
||||
ApiResult.Success(Unit)
|
||||
} else {
|
||||
val errorMessage = ErrorParser.parseError(response)
|
||||
ApiResult.Error(errorMessage, response.status.value)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
ApiResult.Error(e.message ?: "Unknown error occurred")
|
||||
}
|
||||
}
|
||||
|
||||
// Google Sign In
|
||||
suspend fun googleSignIn(request: GoogleSignInRequest): ApiResult<GoogleSignInResponse> {
|
||||
return try {
|
||||
|
||||
Reference in New Issue
Block a user