The synchronization of user permissions in Meteor.js seems to be out of sync with the

As a newcomer to the world of meteorjs and MongoDB, I am currently navigating through "Getting Started with Meteor.js JavaScript Framework" by Isaac Strack. However, I have hit a roadblock in chapter 6 titled "Granting admin permissions." Despite following the author's code, I seem to encounter an issue where when the admin is logged in and I add an item to the list, the item appears for a split second likely due to local caching and server synchronization. What am I missing or doing wrong in this situation? Below is my code:

Meteor.subscribe('Categories');

Meteor.autosubscribe(function() {
    Meteor.subscribe("listdetails",
        Session.get('current_list'));
});

Template.categories.lists = function () {
    return lists.find({},{sort: {Category: 1}});
};

Session.set('adding_category', false);

// More client-side code goes here...

On the server side:

Meteor.startup(function () {
    // Server-side code for publishing data...  
});

In both sections:

// Function related to admin user...

lists.allow({
     // Allow insert, update, remove operations based on admin/user...
 });


HTML Structure:

<head>
  <title>LendLib</title>
</head>

<body>
<div style="float:right; margin-right:20px;">
    {{loginButtons align="right"}}
</div>
<div id="lendlib">
    <div id="categories-container">
        {{> categories}}
    </div>
    <div id="list">
        {{> list}}
    </div>
</div>
</body>

<template name="categories">
    <h2 class="title">
        my stuff
    </h2>
    // HTML template structure...
</template>

<template name="list">
    <ul id="lending_list">
        // Another part of HTML template...
    </ul>
</template>

Answer №1

After many rounds of debugging and trial and error, I finally managed to fix the issue. It turns out the problem was on the server side. Here is the original code snippet:

Meteor.startup(function () {
    Meteor.publish("Categories", function() {
        return lists.find({owner:this.userId},{fields:{Category:1}});
    });
    Meteor.publish("listdetails", function(category_id){
        return lists.find({_id:category_id});
    });
});

And here is the corrected version:

Meteor.startup(function () {
    Meteor.publish("Categories", function() {
        return lists.find({owner:Meteor.userId},{fields:{Category:1}});
    });
    Meteor.publish("listdetails", function(category_id){
        return lists.find({_id:category_id});
    });
});

IMPORTANT: The change was made in line 3 where 'owner:this.userId' was replaced with 'owner:Meteor.userId' as the former does not exist.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The issue of req.file being consistently undefined in Node.js multer

I am having issues trying to upload a file using multer because the req.file is always undefined and the destination folder remains empty: Server: var express = require('express'); var multer = require('multer') var app = express(); ...

Obtain text content using JQuery and AJAX rather than retrieving the value

I am struggling with a dynamic table that needs to perform calculations before submitting, requiring the presence of values. However, I want to submit the text from the options instead of the values. Despite trying various approaches, none of them seem to ...

Check to see if the moment function has been executed and if the resulting output is accurate

I have a function called moment that formats a date received from the server in milliseconds. I am attempting to write tests using Enzyme and Jest to check if the moment function has been called (1), and whether the output of the function matches the expec ...

Experiencing a 404 ERROR while attempting to submit an API POST request for a Hubspot form within a Next.js application

Currently, I am in the process of developing a Hubspot email submission form using nextjs and typescript. However, I am encountering a couple of errors that I need help with. The first error pertains to my 'response' constant, which is declared b ...

Error encountered when attempting to upload an attachment in Sharepoint, resulting in a

Whenever I attempt to upload multiple attachments to my list, I encounter a 'save conflict' error. It seems that Sharepoint is still processing the previous attachment when a new one is submitted. I believe that introducing a delay before sendin ...

Dynamic binding in AngularJS with ng-repeat allows for seamless updating of data

I recently started using a helpful library called Angular Material File input <div layout layout-wrap flex="100" ng-repeat="val in UploadDocuments"> <div flex="100" flex-gt-sm="45"> <div class="md-default-theme" style="margin-le ...

Use the map function to find the highest number within each array

function each(collection, func) { if (Array.isArray(collection)) { for (var i = 0; i < collection.length; i++) { func(collection[i], i); } } else { for (var key in collection) { func(collection[key], key); } } } functi ...

Passing variables in Redirect() without exposing them in the URL; a methodical approach

After scouring the depths of the internet, I have been on a quest to figure out how to seamlessly redirect to a new page on my site while discreetly passing a variable without exposing it in the URL like so: www.test.com/?variable=dont.want.this.here I a ...

The Material UI Drawer stays closed despite the state being set to true

Currently, I am in the process of developing a WebApp utilizing React and Material UI. Despite following numerous tutorials on implementing the Drawer component and poring over the documentation, I am still struggling to grasp its functionality. Even thou ...

Having difficulty toggling checkboxes within a grid using the select all feature

In order to toggle checkboxes for a specific column within a grid, I encountered an issue within the JS "onUPCSelectAll" function with the eval statement displaying the following error message: JS runtime error: Object doesn't support property or meth ...

Tips for transferring a jQuery array to PHP

I am encountering an issue when trying to send a jQuery array to PHP. Initially, I have one form in HTML and upon clicking 'add', I end up with two forms. Afterwards, I input data into the form which is then stored in a jQuery array. However, I a ...

How to selectively import specific modules in three.js using ES6 syntax

I recently integrated the three.js library using NPM with the goal of leveraging its new ES6 modular architecture. This design allows for selective importation of specific modules as outlined in this resource: Threejs - Import via modules. For bundling an ...

Confirm the object received from the API and assign default values

Seeking to extract data from an API and verify if all fields are strings, but if they are missing I aim to assign default values. My intention was to utilize the yup library to validate the object accordingly, ensuring that the returned function is prope ...

Using jQuery, how can you make fixed elements fade as the page scrolls?

How can I make a fixed element, such as a corner ad or notice, fade when the page is scrolled down to a certain point? What would be the most effective method for determining this point: using pixels, percentage, or another way? And how can I implement th ...

Mongoose is filtering out empty objects from arrays of embedded documents

Take a look at the following code snippet showcasing a schema containing 2 arrays. One array is set to Type: [ mongoose.Schema.Types.Mixed ] while the other is set as follows: [ { value: mongoose.Schema.Types.Mixed } ] Below is the actual code u ...

Unable to display content when the button is triggered

I am facing an issue with hiding a div (class="login-form") and displaying it only after clicking the Login button on my HTML page using jQuery. However, despite clicking the button, the login form does not appear. Can anyone help me understand why this ha ...

What is the best way to update the content of a modal using jQuery and AJAX?

Despite previous inquiries on this matter, none of the answers provided have been helpful to me. Therefore, I am addressing the issue again... I am currently developing the frontend of a website that does not involve any backend functionality (no server c ...

Struggling with setting up passport.js. Encountering difficulty fetching the user information

I have a mongodb database where there is a User with the username "testuser", but when I try to login without entering the password, I keep getting an error message saying "failed to login!". I just want to verify that the entered username exists before ch ...

EaselJS BitmapAnimation has delay when using gotoAndPlay

I have created a requirejs module that enhances the functionality of a BitmapAnimation by allowing it to move around the stage at a specific speed and transition to another looped animation once reaching its destination. The issue I am encountering is a n ...

Is the Celery mongoDB broker designed to function through polling mechanisms?

While exploring the Celery documentation for the mongoDB broker, I couldn't find information on whether it operates by polling or not. I came across this insightful blog post that mentioned the possibility of pub/sub with mongoDB, but it's unclea ...