diff --git a/frontend/appflowy_flutter/lib/user/application/user_service.dart b/frontend/appflowy_flutter/lib/user/application/user_service.dart index 77c26ccf1cb4..b985bdf4d49d 100644 --- a/frontend/appflowy_flutter/lib/user/application/user_service.dart +++ b/frontend/appflowy_flutter/lib/user/application/user_service.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'; import 'package:dartz/dartz.dart'; import 'package:appflowy_backend/dispatch/dispatch.dart'; @@ -16,7 +17,10 @@ class UserBackendService { static Future> getCurrentUserProfile() async { - final result = await UserEventGetUserProfile().send(); + final result = await UserEventGetUserProfile().send().then((value) { + value.fold((l) => null, (r) => Log.error(r)); + return value; + }); return result.swap(); } diff --git a/frontend/rust-lib/flowy-user/src/services/session_serde.rs b/frontend/rust-lib/flowy-user/src/services/session_serde.rs index 6e93a267068f..a291b4d9d83f 100644 --- a/frontend/rust-lib/flowy-user/src/services/session_serde.rs +++ b/frontend/rust-lib/flowy-user/src/services/session_serde.rs @@ -6,6 +6,7 @@ use chrono::prelude::*; use serde::de::{Deserializer, MapAccess, Visitor}; use serde::Deserialize; use serde::Serialize; +use serde_json::Value; use flowy_user_deps::entities::{SignInResponse, UserWorkspace}; @@ -44,7 +45,9 @@ impl<'de> Visitor<'de> for SessionVisitor { "user_workspace" => { user_workspace = Some(map.next_value()?); }, - _ => {}, + _ => { + let _ = map.next_value::(); + }, } } let user_id = user_id.ok_or(serde::de::Error::missing_field("user_id"))?; @@ -102,23 +105,40 @@ impl std::convert::From for String { #[cfg(test)] mod tests { use super::*; + use serde_json::json; #[derive(serde::Serialize)] struct OldSession { user_id: i64, workspace_id: String, + name: String, } #[test] fn deserialize_user_workspace_from_workspace_id() { // For historical reasons, the session used to contain a workspace_id field. let old = OldSession { - user_id: 1, - workspace_id: uuid::Uuid::new_v4().to_string(), + user_id: 223238635422486528, + workspace_id: "f58f5492-ee0a-4a9f-8cf1-dacb459a55f6".to_string(), + name: "Me".to_string(), }; let s = serde_json::to_string(&old).unwrap(); let new = serde_json::from_str::(&s).unwrap(); assert_eq!(old.user_id, new.user_id); assert_eq!(old.workspace_id, new.user_workspace.id); + + let json = json!({ + "user_id": 2232386, + "workspace_id": "f58f5492-ee0a-4a9f-8cf1-dacb459a55f6", + "name": "Me", + "token": null, + "email": "0085bfda-85fa-4611-bfbe-25d5a1229f44@appflowy.io" + }); + let new = serde_json::from_value::(json).unwrap(); + assert_eq!(new.user_id, 2232386); + assert_eq!( + new.user_workspace.id, + "f58f5492-ee0a-4a9f-8cf1-dacb459a55f6" + ); } }