diff --git a/native/identity-service/identity-service-context-provider.react.js b/native/identity-service/identity-service-context-provider.react.js --- a/native/identity-service/identity-service-context-provider.react.js +++ b/native/identity-service/identity-service-context-provider.react.js @@ -79,12 +79,8 @@ return { deviceID, userID, accessToken }; }, [accessToken]); - const processAuthResult = async ( - authResult: string, - username: string, - deviceID: string, - ) => { - const { userID, accessToken: token } = JSON.parse(authResult); + const processAuthResult = async (authResult: string, deviceID: string) => { + const { userID, accessToken: token, username } = JSON.parse(authResult); const identityAuthResult = { accessToken: token, userID, @@ -372,7 +368,6 @@ return await processAuthResult( registrationResult, - username, primaryIdentityPublicKeys.ed25519, ); }, @@ -414,7 +409,6 @@ return await processAuthResult( registrationResult, - username, primaryIdentityPublicKeys.ed25519, ); }, @@ -438,7 +432,6 @@ return await processAuthResult( loginResult, - username, primaryIdentityPublicKeys.ed25519, ); }, @@ -478,7 +471,6 @@ return await processAuthResult( registrationResult, - walletAddress, primaryIdentityPublicKeys.ed25519, ); }, @@ -521,7 +513,6 @@ return await processAuthResult( registrationResult, - walletAddress, primaryIdentityPublicKeys.ed25519, ); }, @@ -549,7 +540,6 @@ return await processAuthResult( loginResult, - walletAddress, primaryIdentityPublicKeys.ed25519, ); }, @@ -582,21 +572,11 @@ getOneTimeKeyValues(contentOneTimeKeys), getOneTimeKeyValues(notificationsOneTimeKeys), ); - const { accessToken: token } = JSON.parse(registrationResult); - - const identityAuthResult = { accessToken: token, userID, username: '' }; - const validatedResult = assertWithValidator( - identityAuthResult, - identityAuthResultValidator, - ); - await commCoreModule.setCommServicesAuthMetadata( - validatedResult.userID, + return await processAuthResult( + registrationResult, primaryIdentityPublicKeys.ed25519, - validatedResult.accessToken, ); - - return validatedResult; }, generateNonce: commRustModule.generateNonce, getDeviceListHistoryForUser: async ( diff --git a/native/native_rust_library/src/identity.rs b/native/native_rust_library/src/identity.rs --- a/native/native_rust_library/src/identity.rs +++ b/native/native_rust_library/src/identity.rs @@ -143,24 +143,28 @@ pub initial_device_list: String, } +/// Counterpart of proto [`AuthResponse`] message +/// that implements the `Serialize` trait. #[derive(Serialize)] #[serde(rename_all = "camelCase")] -pub struct UserIDAndDeviceAccessToken { +pub struct IdentityAuthResult { #[serde(rename = "userID")] user_id: String, access_token: String, + username: String, } -impl From for UserIDAndDeviceAccessToken { +impl From for IdentityAuthResult { fn from(value: AuthResponse) -> Self { let AuthResponse { user_id, access_token, - .. + username, } = value; Self { user_id, access_token, + username, } } } diff --git a/native/native_rust_library/src/identity/login.rs b/native/native_rust_library/src/identity/login.rs --- a/native/native_rust_library/src/identity/login.rs +++ b/native/native_rust_library/src/identity/login.rs @@ -9,9 +9,7 @@ }; use tracing::instrument; -use super::{ - LogInPasswordUserInfo, LogInWalletUserInfo, UserIDAndDeviceAccessToken, -}; +use super::{IdentityAuthResult, LogInPasswordUserInfo, LogInWalletUserInfo}; use crate::utils::jsi_callbacks::handle_string_result_as_callback; use crate::{Error, CODE_VERSION, DEVICE_TYPE, IDENTITY_SOCKET_ADDR, RUNTIME}; @@ -191,9 +189,8 @@ .log_in_password_user_finish(login_finish_request) .await? .into_inner(); - let user_id_and_access_token = - UserIDAndDeviceAccessToken::from(login_finish_response); - Ok(serde_json::to_string(&user_id_and_access_token)?) + let auth_result = IdentityAuthResult::from(login_finish_response); + Ok(serde_json::to_string(&auth_result)?) } async fn log_in_wallet_user_helper( @@ -219,9 +216,8 @@ .await? .into_inner(); - let user_id_and_access_token = - UserIDAndDeviceAccessToken::from(login_response); - Ok(serde_json::to_string(&user_id_and_access_token)?) + let auth_result = IdentityAuthResult::from(login_response); + Ok(serde_json::to_string(&auth_result)?) } async fn upload_secondary_device_keys_and_log_in_helper( @@ -249,8 +245,8 @@ .await? .into_inner(); - let user_id_and_access_token = UserIDAndDeviceAccessToken::from(response); - Ok(serde_json::to_string(&user_id_and_access_token)?) + let auth_result = IdentityAuthResult::from(response); + Ok(serde_json::to_string(&auth_result)?) } async fn log_in_existing_device_helper( @@ -278,6 +274,6 @@ .await? .into_inner(); - let user_id_and_access_token = UserIDAndDeviceAccessToken::from(response); - Ok(serde_json::to_string(&user_id_and_access_token)?) + let auth_result = IdentityAuthResult::from(response); + Ok(serde_json::to_string(&auth_result)?) } diff --git a/native/native_rust_library/src/identity/registration.rs b/native/native_rust_library/src/identity/registration.rs --- a/native/native_rust_library/src/identity/registration.rs +++ b/native/native_rust_library/src/identity/registration.rs @@ -14,9 +14,9 @@ use tracing::instrument; use super::{ - farcaster::farcaster_id_string_to_option, RegisterPasswordUserInfo, - RegisterReservedPasswordUserInfo, RegisterReservedWalletUserInfo, - RegisterWalletUserInfo, UserIDAndDeviceAccessToken, + farcaster::farcaster_id_string_to_option, IdentityAuthResult, + RegisterPasswordUserInfo, RegisterReservedPasswordUserInfo, + RegisterReservedWalletUserInfo, RegisterWalletUserInfo, }; pub mod ffi { @@ -228,9 +228,8 @@ .register_password_user_finish(registration_finish_request) .await? .into_inner(); - let user_id_and_access_token = - UserIDAndDeviceAccessToken::from(registration_finish_response); - Ok(serde_json::to_string(&user_id_and_access_token)?) + let auth_result = IdentityAuthResult::from(registration_finish_response); + Ok(serde_json::to_string(&auth_result)?) } async fn register_reserved_password_user_helper( @@ -277,9 +276,8 @@ .register_password_user_finish(registration_finish_request) .await? .into_inner(); - let user_id_and_access_token = - UserIDAndDeviceAccessToken::from(registration_finish_response); - Ok(serde_json::to_string(&user_id_and_access_token)?) + let auth_result = IdentityAuthResult::from(registration_finish_response); + Ok(serde_json::to_string(&auth_result)?) } async fn register_wallet_user_helper( @@ -305,11 +303,8 @@ .await? .into_inner(); - let user_id_and_access_token = UserIDAndDeviceAccessToken { - user_id: registration_response.user_id, - access_token: registration_response.access_token, - }; - Ok(serde_json::to_string(&user_id_and_access_token)?) + let auth_result = IdentityAuthResult::from(registration_response); + Ok(serde_json::to_string(&auth_result)?) } async fn register_reserved_wallet_user_helper( @@ -336,9 +331,6 @@ .await? .into_inner(); - let user_id_and_access_token = UserIDAndDeviceAccessToken { - user_id: registration_response.user_id, - access_token: registration_response.access_token, - }; - Ok(serde_json::to_string(&user_id_and_access_token)?) + let auth_result = IdentityAuthResult::from(registration_response); + Ok(serde_json::to_string(&auth_result)?) }