realm / realm-object-server

Tracking of issues related to the Realm Object Server and other general issues not related to the specific SDK's
https://realm.io
293 stars 36 forks source link

Several feature requests related to User object, object synchronization and Realm sharing #142

Open Taco55 opened 7 years ago

Taco55 commented 7 years ago

After some time using Realm Object Server I think it is really great and I hope to use it in my future apps. For my current demands, however, I feel that some functionality is missing in the Realm API's (or I just overlooked them).

Some features I would really like to see in future version (hopefully I am allowed to put them in a single issue) are:

1) Determine "register status" of a user when registered/logged in to Realm Object Server utilizing third-party authentication Login with Facebook, Google or CloudKit works fine. However, I would like to seed the user's Realm with some initial data when the user is registered. Since I use a single button for both login and signup I need a way to determine whether a user is registered (or logged in another time). Although I could check for an empty Realm, this is not desirable since an existing Realm should be synced first. It would be very desirable to be able to obtain the "register status" in a more generic way. For example as a boolean property in the completion handler of the SyncUser.logIn method. Or even better for me, to be able to check whether some specific data is available in a Realm. But this requires the ability to synchronize this data first (before the rest of the data is downloaded) to keep the response as fast as possible. See also feature request 2).

2) Prioritizing of objects to synchronize by ROS In my app I store several settings and user data in a synchronized Realm. However, after login this data should preferably be synchronized first before the app navigates to the main view controller. For example, the settings data determine some UI behavior, such as a background color that may differ per user. Although Realm notifications could be used to update the UI after the data becomes available, the result might be that the layout may change completely when the fetched settings differ from the default. To avoid this, it would be better to wait until settings and user data are available before showing the main view. By prioritizing the downloading of settings and user data, the time to wait could be minimized. Subsequently, other data can in the usual way using Realm notifications. Prioritizing of data should only be once. In this case, only after a user is logged in.

3) Adding more information to SyncUser (User object in admin Realm) When a user signs up, very often both e-mail and name should be provided. Since e-mail cannot be stored in SyncUser, I store this data in a (custom) user object in a synchronized Realm. Although this just works, it is not ideal in my case. Main reason is that these data should be available before navigating to the main view controller. But also because the user info is preferably be available on User in order to lookup users based on these properties (see request 5). Two solutions would fit in my case:

In the latter situation, however, it may be required to indicate in SyncUser.logIn whether registration is performed with a username or email address. Currently, it can be both. Is this something that will change in the future?

4) Adding more details in the Realm browser Somewhat related to the previous request. In the Admin Realm it is something difficult to identify what accounts are linked to a user. Visually, it would be clearer to identify a User object on email (or username) instead of an ID. However, when more data is added to this object (as requested in 3) this problem should be solved. Nevertheless, when opening a user's Realm via the realm browser, it is still hard to open the correct one since it is only based on ID's and thus requires to open the admin Realm first (and to discover the User that owns a specific Realm). Would it be possible to, for example, add a column indicating which user owns a specific Realm?

5) Lookup SyncUsers via Realm API This request is already proposed, but I mention it again since it is really desirable. In my case, it would be required to share a Realm with a user that could be looked up based on e-mail address (or username in the general case, depending on how users are registered). Furthermore, when a SyncPermissionOfferResponse could be directly added to the "other" user's Realm, there is no need to send a token by e-mail (or whatever method). I understand that this may not as easy as it sounds, since the other user should be able to refuse sharing et cetera. But it would be ideal to be able to share data from inside and app only.

6) Link multiple accounts to a single user Currently, users are allowed to login using four methods. The ability to link the corresponding Accounts to a User object (i.e. from the user that is currently logged in) would very desirable. However, in case an account was already created (and thus linked to another User object), this might be a problem though. For my case I could show a message indicating that this account is already used to login and provide two options: 1. to delete a Realm or 2. to copy the data to the Realm of the current User. Ad 1. This situation might give other problems when the data is in use on another device, so it may not be easily to overcome and not a real option. Ad 2. No realm is removed. When another device is connected to the "old" Realm (i.e. of the user of which the account should be linked to the current user) a crash is avoided. Furthermore, the data of the Realm that will be connected to the selected account will be updated when connected to ROS or, when it regards shared data, the SyncPermissionOfferResponse should be updated to allow access to the Realm of the new Realm (i.e. of the current user). Probably, this is just a way too simple thought, but hopefully there will be a possibility to implement this functionality.

teotwaki commented 7 years ago

Hi @Taco55,

Major props, and many thanks for this amazing report. I'm sure @bigfish24 will also have some input, but as an immediate response:

  1. This is an oversight in our API. I don't think you're first one to request this, as it breaks some common UX/UI flows in mobile apps.
  2. Prioritisation is going to be very tough to implement, though not undoable. In its current state, I would say that this is handled by the waitForDownload API, which allows you to wait until the first major sync (initial Realm file download) has been downloaded and applied locally, not just new insertions to specific collections.
  3. This is roadmapped, and is currently being worked on.
  4. We don't really want our users to use the browser to access the Admin Realm. It's more of an internal file that we don't intend to expose in the long term. We will be providing APIs to work with users instead.
  5. Included in the above.
  6. This is actually technically possible, but I don't think we have an API in the client SDKs to perform the "binding". The way I imagine this, would be to have the typical "Link another account" UI in the user's settings/preferences pane of the app. The end-user can then log-in, and the server would simply add that authentication to the user's identity. I definitely want to expose this and make it useable soon.

I realise I'm not giving a lot of information beyond what is already available in this repo and in the docs, but I hope it adds some clarity. To me, it confirms that what we're working on matches the needs of our users, and that's always good :D.

bigfish24 commented 7 years ago

@Taco55 seems I missed responding to this earlier. Would like to ask some clarifying comments:

2) Prioritizing of objects to synchronize by ROS

In my app I store several settings and user data in a synchronized Realm. However, after login this data should preferably be synchronized first before the app navigates to the main view controller. For example, the settings data determine some UI behavior, such as a background color that may differ per user. Although Realm notifications could be used to update the UI after the data becomes available, the result might be that the layout may change completely when the fetched settings differ from the default. To avoid this, it would be better to wait until settings and user data are available before showing the main view. By prioritizing the downloading of settings and user data, the time to wait could be minimized. Subsequently, other data can in the usual way using Realm notifications.

You could achieve this today by separating the data into multiple Realms, such that you can control when you open them and they initiate sync. Furthermore, you can use the progress notifications to track when the initial download is complete. We are working on another simple "Download Realm" API to automate this which should be out in the coming weeks.

3) Adding more information to SyncUser (User object in admin Realm) This is coming in the next couple weeks as well. We are actively working on it, including a user search API against the additional data.

4) Adding more details in the Realm browser Also coming soon. There will be a browser in the ROS dashboard where you can look up Realms via the additional data as explained in 3 above.

5) Lookup SyncUsers via Realm API See above, this is coming along side the additional data on the User.

6) Link multiple accounts to a single user On the roadmap, but not actively being worked on yet.

Taco55 commented 7 years ago

Thanks for your additional information and great to hear that most of the functionality I mentioned will be added in next versions!

2) Prioritizing of objects to synchronize by ROS

You could achieve this today by separating the data into multiple Realms, such that you can control when you open them and they initiate sync. Furthermore, you can use the progress notifications to track when the initial download is complete. We are working on another simple "Download Realm" API to automate this which should be out in the coming weeks.

This seems a good suggestion and I just started to implement it this way. Although it works perfect for unidirectional syncing, I don't get it working in a bi-directional situation. It seems that only the first accessed (shared) Realm will be synced in memory, while a subsequent Realm does get synced at all (also, progress notifications do not get triggered for subsequent Realms). Since this problem does not seem to happen for Realms owned by the user, I wondered whether this issue might be related to the issue I reported on fine-grained notifications. Therefore, I will just wait for the analysis on that and switch back to a single Realm for now.

The additional Download Realm API would be a nice feature. Would this also make it possible to determine whether a user is already registered (i.e. or at least by indicating that a Realm is empty)? In that case, it would also solve the point I mentioned in 1) and would be even greater!

Keep up the good work!

bigfish24 commented 7 years ago

It would be great to understand why you are not seeing syncing from multiple Realms. That doesn't add up to any known issues as we have a demo app that heavily uses several Realms and there are no issues.

I filed an issue for determining if a user is already registered, so not sure the download Realm would solve that by itself.

michael-mckenna commented 7 years ago

What's the extent of #3? Will we be able to add custom fields to the SyncUser object in the future?