1👍
As per my reply in the Meteor forums, you are $subscribing
to currentUser
and currentUserId
instead of defining them as reactive data. Also, you don’t need to publish/subscribe to the current user’s userId because it is always available in the client as Meteor.userId()
.
Meteor.userId()
is a reactive data source and you can convert it into a Vue reactive property using vue-meteor-tracker
like this: e.g. within App.vue:
<script>
import { Meteor } from 'meteor/meteor';
export default {
meteor: {
currentUserId() {
return Meteor.userId();
},
},
}
</script>
Then you can use it within any template as, e.g. v-if="$root.currentUserId"
, or within any component’s code as this.$root.currentUserId
.
In this simple example I have used the root Vue instance as an easily accessible global data store, but it’s more widely accepted to use a dedicated data store, or use Vuex.
0👍
Meteor.user() will always return undefined when you’re not logged in. So your login logic isn’t working. I’m not sure what you’re doing, but you should be using ‘Meteor.loginWithPassword’ to do your logging in on the client. What’s ‘loginUserForDomain’ for?
I don’t understand Meteor.loginWithPassword(email, password);
as both ’email’ and ‘password’ would be undefined (should it be this.user.email?). Also does ‘this.user.email’ console.log anything?