diff --git a/lib/user-methods.js b/lib/user-methods.js index b0f4210c..9d999e75 100644 --- a/lib/user-methods.js +++ b/lib/user-methods.js @@ -91,7 +91,7 @@ function refreshAccessToken(user, localRealmPath, realmUrl) { // Look up a fresh instance of the user. // We do this because in React Native Remote Debugging // `Realm.clearTestState()` will have invalidated the user object - let newUser = user.constructor.all[user.identity]; + let newUser = user.constructor._getExistingUser(user.server, user.identity); if (!newUser) { return; } diff --git a/src/js_sync.hpp b/src/js_sync.hpp index d373d863..38e8f9da 100644 --- a/src/js_sync.hpp +++ b/src/js_sync.hpp @@ -59,6 +59,7 @@ class UserClass : public ClassDefinition { using Value = js::Value; using Function = js::Function; using ReturnValue = js::ReturnValue; + using Arguments = js::Arguments; public: std::string const name = "User"; @@ -79,10 +80,12 @@ public: static void create_user(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &); static void admin_user(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void get_existing_user(ContextType, ObjectType, Arguments, ReturnValue&); MethodMap const static_methods = { {"createUser", wrap}, - {"_adminUser", wrap} + {"_adminUser", wrap}, + {"_getExistingUser", wrap}, }; /*static void current_user(ContextType ctx, ObjectType object, ReturnValue &return_value);*/ @@ -153,6 +156,18 @@ void UserClass::admin_user(ContextType ctx, FunctionType, ObjectType this_obj return_value.set(create_object>(ctx, user)); } +template +void UserClass::get_existing_user(ContextType ctx, ObjectType, Arguments arguments, ReturnValue& return_value) { + arguments.validate_count(2); + SharedUser *user = new SharedUser(syncManagerShared().get_existing_logged_in_user( + SyncUserIdentifier{ + Value::validated_to_string(ctx, arguments[1], "identity"), + Value::validated_to_string(ctx, arguments[0], "authServerUrl"), + } + )); + return_value.set(create_object>(ctx, user)); +} + template void UserClass::all_users(ContextType ctx, ObjectType object, ReturnValue &return_value) { auto users = Object::create_empty(ctx);