Comments (19)
Try with 1.1.13. It shouldn't be null unless you're not signed in.
from react-native-meteor-offline.
Ok I'll test right now.
Very quick :)
from react-native-meteor-offline.
No, it is still null.
When I disconnect the server ('Disconnected from DDP server.'), the user is still detected. But as soon as I refresh the react native app, user is null.
It happens only with the 'users' collection.
from react-native-meteor-offline.
Did you try in the example, or do you have a repo that I can test? It works for me in the example (if you go to "Profile").
BTW, in case you don't already know about it, there's a preference pane for osx called "Link Conditioner" that allows you to quickly test network connectivity, without jumping on and off wifi.
from react-native-meteor-offline.
No I didn't try in the example, but I will in 7 hours when I'm back home.
I also have a repo, I will give it to you but I need to commit tonight.
Oh I didn't know this spec, perfect cheers for the info !
from react-native-meteor-offline.
I just tested with the example and it doesn't work (with the version 1.1.13).
The user is not persisted offline (still null).
I have added console.log(user); line 28 in index.js file (RNApp).
Then disconnected the meteor server.
Then refreshed the RNApp.
from react-native-meteor-offline.
[FIXED]
I don't think this is a good pattern, but I have replaced user: Meteor.user(),
by user: Meteor.collection('users').findOne()
in createContainer
and the user object is persisted offline.
from react-native-meteor-offline.
I'll take a look, but in the meantime that's not a bad solution. react-native-meteor
does that on the backend, I believe.
from react-native-meteor-offline.
Ok I think I got it.
Actually the problem is not your package but the react-native-meteor
one (User.js file).
When you do a Meteor.user() if it doesn't find a this._userIdSaved, it returns null.
if it finds it, it returns this.collection('users').findOne(this._userIdSaved).
user() {
if(!this._userIdSaved) return null;
return this.collection('users').findOne(this._userIdSaved);
}
This is exactly the same with Meteor.userId():
userId() {
if(!this._userIdSaved) return null;
const user = this.collection('users').findOne(this._userIdSaved);
return user && user._id;
}
The this._userIdSaved
is defined when login, maybe we should ask to contributors of this repo to set one more item (result.id at the first login on the app) in the Asyncstorage:
_handleLoginCallback(err, result) {
if(!err) {//save user id and token
AsyncStorage.setItem(TOKEN_KEY, result.token);
Data._tokenIdSaved = result.token;
this._userIdSaved = result.id;
Data.notify('onLogin');
} else {
Data.notify('onLoginFailure');
this.handleLogout();
}
Data.notify('change');
},
from react-native-meteor-offline.
That makes sense. So, the _handleLoginCallback
should be fine, it's the _loginWithToken
that calls it in a callback from a Meteor.call
, which then requires a connection. Probably best would be to call _handleLoginCallback
from initMeteorRedux
. Thoughts?
from react-native-meteor-offline.
Yeah I think you're right, calling _handleLoginCallback()
would be the best option.
from react-native-meteor-offline.
Huh, this is tricky... The userId is obtained from the Meteor.call
, not from AsyncStorage, so I can't pass the required parameters. Ideas?
from react-native-meteor-offline.
Yeah a bit complicated ...
Why not just create 2 functions in your package for now like:
user() {
return Meteor.collection('users').findOne();
}
and
userId() {
const user = Meteor.collection('users').findOne();
return user && user._id;
}
It will avoid going through this._userIdSaved
.
It won't make us in trouble because there will be only one user using the app (normally).
And then asking for react-native-meteor contributors to register this._userIdSaved in the asyncstorage ...
from react-native-meteor-offline.
If you have more than one user, is that guaranteed to return the logged in user?
from react-native-meteor-offline.
With autopublish package I don't know. (I think it should work)
But if you remove it, then you just have to create a custom publish for user data:
Meteor.publish("userData", function () {
if (this.userId) {
return Meteor.users.find({_id: this.userId});
} else {
this.ready();
}
});
from react-native-meteor-offline.
In fact I think it works in every cases, even without the above snippet
from react-native-meteor-offline.
But I mean if you have multiple users, how do you know the user you get back is the logged in one? You could have 100 users and it could return any random one, couldn't it?
from react-native-meteor-offline.
You have the const TOKEN_KEY = 'reactnativemeteor_usertoken';
that is stored on the Asyncstorage. So it is linked to a unique userId.
Then, once you're connected you will get info of the user connected with the token, even if there are 100 other users on the database
from react-native-meteor-offline.
I added MO.user()
in v2.2.0
from react-native-meteor-offline.
Related Issues (20)
- Last Redux State is not written to disk HOT 5
- _.clone(state) or _.cloneDeep(state.prop) HOT 4
- How to write record HOT 2
- [Error] Expected listener to be a function HOT 2
- Crash when subscribing HOT 1
- How to sync inserts/updates after resuming connection HOT 3
- Package not bundling HOT 3
- Unable to resolve module 'redux-persist' when trying to npm link HOT 1
- 'cleared' field ignored in ddp event listeners HOT 3
- Can't get online insert to work HOT 1
- Create user issues HOT 1
- Subsciptions keep on reloading HOT 1
- MO.user() after successful Meteor.logout() then go offline.
- TypeError: undefined is not an object (evaluating '(0, _reactNativeMeteor.getData)().db[collection].remove') HOT 1
- Cleanup method needed when user logged out and new one connected HOT 3
- undefined is not an object (evaluating 'state[collection][id]') HOT 2
- offline property of MeteorOffline is always false
- with expo sdk32 : invalid attempt to spread non-iterable instance HOT 6
- Can you give me the example of a function component? HOT 1
- Upgrade to meteorrn/core HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-meteor-offline.