Open Diwei-Chen opened 7 years ago
loginWithPassword()
callback doesn't have arguments on success.
Docs: http://docs.meteor.com/api/accounts.html#Meteor-loginWithPassword
The correct way is to wait for Meteor to update props to component:
export default createContainer(params=>{
return {
user: Meteor.user()
};
}, MyComponent)
@twairtall Ah right! Thank you very much.
@twairball I am doing this way however the container isn't refreshed after Accounts.createUser
. In that case Meteor.user()
is still undefined. If I refresh the app then works.
RE: Accounts.createUser
I'm not a meteor expert, but I think most authentication systems don't login automatically after registration, so this pattern is expected.
For me, I login explicitly after registration.
What Meteor variable(s) or way(s) can you determine you have log in succeeded tho? After loginWithPassword()
?
@Diwei-Chen use Meteor.user() in your createContainer function. It's Reactive.
Sent from my OnePlus ONEPLUS A3003 using FastHub
User() or userId(), which is reactive, is not null
Adam Ginsburg adam.ginsburg@buzzy.buzz tel: +61 411 151 732 www.buzzy.buzz
On 5 Jul 2017, at 4:26 pm, Diwei-Chen notifications@github.com wrote:
What Meteor variable(s) or way(s) can you determine you have log in succeeded tho? After loginWithPassword()?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
I found Meteor.user() is reactive when connecting to local server, but not for remote server. Anyone else has this issue?
Please share your code. Are you using within createcontainer?
Sent from my OnePlus ONEPLUS A3003 using FastHub
Thanks @Nauzer
The scenario is, after a user clicks Login button it will call Meteor.loginWithPassword(...) and the component will wait till the user object comes back and dispatches two actions. But the problem is when I connect to my remote server, Meteor.user() is always null, but it works fine when connects with local server.
Here are some of the codes, hope I was missing something..
shouldComponentUpdate(nextProps, nextStates) {
if (nextProps.user) {
this.props.dispatch({ type: Type.LOGIN_USER_SUCCESS, payload: { user: nextProps.user } });
this.props.navigation.dispatch({ type: Type.GO_TO_MAIN });
}
return true;
}
const LoginFormContainer = createContainer((props) => {
return {
user: Meteor.user()
}
}, LoginForm);
That is what I'm doing as well and should work. What happens if you output anything in your render function on the basis of Meteor.user() 's value?
render() {
if(this.props.user) {
return (
<Text>We have a user</Text>
)
} else {
return (
<Text>No we don't</Text>
)
}
}
It returns No we don't
in my case. I found what interesting is the users
collection is always added through listening to ddp connection Meteor.ddp.on('added', (obj, ...args)
and the user object is in this collection.
I had this issue because a few of our users had ids generated by non-meteor apis and had non-meteor _ids. react-native-meteor will log in and issue a token with the non-meteor id but after some debugging it would appear that the collection.findOne returns null give an _id type it isn't expecting. I have tested with a regular meteor app and login works so it would appear to be an issue with react-native-meteor.
Edit: this bug comes from minimongo-cache added a hacky fix to https://github.com/jackkav/minimongo-cache/
I am still facing this issue, did anyone ever come up with a solution?
@jeffreyflynt maybe try the new withTracker which replaces createContainer, docs here https://guide.meteor.com/react.html#using-withTracker and put the Meteor.userId() within the withTracker section, something like:
const mapMeteorToProps = (props) => {
return {
userId: Meteor.userId(),
};
};
export default withTracker( mapMeteorToProps )( ClassName );
And in the class (ClassName in this example), use this.props.userId
Thanks for this @jon617 ! It worked for us & also appreciated a link to the Meteor documentation - which I found to be written with helpful unambiguous language.
Hi there,
I met an issue when after doing
Meteor.loginWithPassword()
, and in the callback didconst user = Meteor.user()
, it showsuser === null
.This happened when my app connected with URL
wss://<DOMAIN_NAME>/websocket
, but when the app connected with a local hostws://localhost:3000/websocket
, it works completely fine, ie it returns the user object as expected.Am I doing anything wrong with the package or wws stuff?
FYI @adamgins
Regards,