Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializing and deserializing a User #1276

Closed
kraenhansen opened this issue Sep 1, 2017 · 1 comment · Fixed by #1996
Closed

Serializing and deserializing a User #1276

kraenhansen opened this issue Sep 1, 2017 · 1 comment · Fixed by #1996
Assignees

Comments

@kraenhansen
Copy link
Member

kraenhansen commented Sep 1, 2017

Goals

In a multi process environment, like an electron app, it would be valuable to be able to pass users between processes in a serialized form.

Expected Results

I would expect that when logging in to ROS and serializing the resulting user I would get an object as follows:

Realm.Sync.User.register("http://localhost:9080", username, password, (err, user) => {
    const userString = JSON.stringify(user);
    // user === "{token: "...", identity: "some-username", server: "http://localhost:9080", isAdmin: false }"

This could be fixed by implementing a toJSON method on the Realm.Sync.User class: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior

In addition to this, it would be valuable to create a Realm.Sync.User from a JSON representation. This could be implemented with a fromJSON method on the user.

Actual Results

Serializing a Realm.Sync.User (JSON.stringify(user)) gives you the string representation of an empty object ({}) and the fields of a User are all implemented as getters that cannot be set.

Steps to Reproduce

  1. Login or register a user through the Realm Object Server.
  2. Serialize the user using JSON.stringify(user)
  3. Observe the disappointing result

Code Sample

See "Expected Results"

Version of Realm and Tooling

  • Realm JS SDK Version: 2.0.0-rc5
@kraenhansen kraenhansen changed the title Serializing a User shouldn't give "{}" Serializing and deserializing a User Sep 1, 2017
@ivanquirino
Copy link

a toJSON in realm objects and collections would be great. Useful for debugging and serialization support.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants