403 Unauthorized when updating Meteor User - angularjs

I'm getting a 403 when trying to update a user's profile using meteor-angular. Unfortunately, it's not very descriptive -- the complete error is:
{
details: undefined
error: 403
errorType: "Meteor.Error"
message: "Access denied [403]"
reason: "Access denied"
}
I'm under the impression that I don't need to add anything to the server side, but I added to try to get some visibility into what the actual update request looked like.
Meteor.users.deny {
update: (userId, user, fields, modifier) ->
console.log("meteor deny!")
console.log(userId, user._id)
console.log(fields, modifier)
false
}
Meteor.users.allow {
update: (userId, user, fields, modifier) ->
console.log("allow", arguments)
true
}
For debugging. In the logs, I see
I20150707-22:14:22.955(-6)? meteor deny!
I20150707-22:14:22.956(-6)? Hk83p9hieEBYHhzo6 Hk83p9hieEBYHhzo6
I20150707-22:14:22.956(-6)? [ 'profile' ] { '$set': { 'profile.name': 'ben', 'profile.gender': 'male' } }
Which is exactly what I would expect to see and appears to be what is required when looking at the docs -- i.e. a user is editing their own profile and the $set is using dot notation. I'm triggering the update from the client, basically using pretty plain angular. The interesting bits are
....
$scope.user = $meteor.object $meteor.getCollectionByName("users"), $stateParams.userId
$scope.save = () ->
if $scope.form.$valid
$scope.user.save({ 'profile.name': $scope.user.profile.name, 'profile.gender': $scope.user.profile.gender}).then(
(numberOfDocs) ->
console.log 'save successful, docs affected ', numberOfDocs
(error) ->
console.log 'save error ', error
)
I'm sort of at a loss for what to try next. My packages are
meteor-platform
urigo:angular
angularui:angular-ui-router
coffeescript
mquandalle:stylus
civilframe:angular-jade
twbs:bootstrap
angularui:angular-ui-bootstrap
mquandalle:bower
tmeasday:publish-counts
aldeed:collection2
angularutils:pagination
accounts-ui
okland:accounts-phone
accounts-base

Not a full answer, but to fix your problem immediately, just create a method that updates a users profile server side. Just check that a user is only trying to edit his own profile.

Related

Getting message: "Match failed [400]", errorType: "Meteor.Error" when using rocketchat methods(loadHistory) in Reactjs

I am trying to integrate Rocket chat to my application using asteroid but when I use Rocket.chat's LoadHistory method I get {isClientSafe: true, error: 400, reason: "Match failed", message: "Match failed [400]", errorType: "Meteor.Error"}. To be clear, I have never used Rocket.chat or Asteroid before. However some methods are working flawlessly.
/**
* Calls a server-side method with the specified arguments.
* #param method string required: the name of the method to call
* #param params [param1, param2, ...] any optional: parameters passed to the
server method
* #return Promise resolved, rejected
*/
let asteroidMethods = function (method, param){
return socket.call(method, param)
};
getMessageHistory = (lastMessage) => {
let param =[ lastMessage.rid, null, 50, lastMessage['ts']['$date']];
asteroidMethods("loadHistory", param).then(res=>{
console.log(res)
}).catch(e=>{
console.log(e)
})
}
Since the Match failed response is a rather generic one, there're several potential issues causing your error. For example, the lastMessage.rid could be empty.
With your problem, the Rocket.Chat server logs shall give you more information about the underlaying problem. For that, Rocket.Chat offers a nice way of accessing the server logs through the user interface:
Log in to the Rocket.Chat admin UI as admin user
Ensure the Log Level to be very verbose -> Level 2 (https://example.com/admin/Logs)
Visit the log view (https://example.com/admin/view-logs)
Execute your code once
Example
I've set my roomId to 42 in an example request:
connection.method('loadHistory', [42, roomId, oldestMessageDate, 15])
That triggers the following log event with very detailed information:
Exception while invoking method 'loadHistory'
{ Error: Match error: Expected string, got number }
With that information, you should be able to identify the actual issue behind your request.

Angularjs 1: delete an item, but item still exist until refresh

Here is my simple angular 1 app.
Source code here.
Basically it is a copy of this.
I am able to do CRUD operations. The issue is that, when I delete a record. It redirects back to the home page. The record I deleted is still here. If I refresh the page, it is gone.
Is it a way to delete a record and then after redirect, I should see the latest list?
Update 1:
Unfortunately, it is still unresolved. Something strange that it seems the promise in resolve is cached. I added a few console.log inside the code. You can see the code flow. Open chrome developer tool to see it.
i review you code , the problem is here:
this.deleteContact = function(contactId) {
var url = backend_server + "/contacts/" + contactId;
// actually http delete
return $http.delete(url)
.then(function(response) {
return response;
}, function(response) {
alert("Error deleting this contact.");
console.log(response);
});
}
if you have service to manage your contact use there to call your server to delete the contact.
the reason you cannot delete without refresh is:
your delete from DB but not from angular array.
must review (update the scope (array))
your code is hard to read , i have suggestion for you, using:
broserfy , watchify
lodash
and backen use mvc
You delete it remotely but not locally. So you can see result only after refreshing (only after you requesting updated data from server). You need to update your local contacts after you succeed on server side.
$scope.deleteContact = function(contactId) {
Contacts.deleteContact(contactId).then(function(data){
...
//DELETE YOU LOCAL CONTACT HERE
...
$location.path("/");
});
}
I didn't look deeply into your code, so I can't say how exactly you should do it, but as I see you keep your local contacts in $scope.contacts in your ListController.

CloudKit Database Query Issue

I just started to build a web app, and for some reason I have to use CloudKit and its database for my backend.
I tried a really stupid database query and intended to see the results at frontend. Here is my code :
CloudKit.configure({
containers: [{
containerIdentifier: my identifier,
apiToken: my api token,
environment: 'development'
}]
});
var container = CloudKit.getDefaultContainer();
var DB = container.publicCloudDatabase;
var query = {recordType : 'Request'};
DB.performQuery(query).then(function(response){
if (response.hasErrors) {
throw response.errors[0];
} else {
console.log(response);
}
});
However, I keep getting this authentication_failed error :
cloudkit.js:3 Uncaught (in promise) t {_ckErrorCode: "AUTHENTICATION_FAILED", _uuid: "4ef8ba12-eb00-408f-9a1c-6e8b4de84ec8", _reason: "no auth method found", _serverErrorCode: "AUTHENTICATION_FAILED", _extensionErrorCode: undefined…}
I tried to fetch a record with the same code, and it works fine.
So is the error caused by unlogged in users? If so, Is there any configurations in CloudKit Dashboard to allow users from certain URL to query the database without logging in?
Thanks!
Check the containerIdentifier value. I had a similar issue when I used the identifier name of the API Token instead of the generated iCloud identifier from the app name. You can also verify your token with the link Test with CloudKit Catalog

Backbone.js save error

I am scratching my head over an issue with backbone...
I have a backbone view, with an event which calls a function that saves the current model.
Its a simple form, in the view I do some validation before syncing the model.
this.model.save({
completed : completed,
company : company,
revenue : revenue,
term : term,
comments : comments,
probability : probability
},
{
success: function (model, response) {
console.log('success', model, response);
Evision.trackRouter.navigate("tracker/", {trigger: true});
},
error: function (model, response) {
console.log('error', model, response);
}
}
;
After success is fired it returns me back to my collection of models, where I can select another model to edit, its at this point when i attempt to save that i receive in my console and Chrome crashes.
If i expand this error it is indicating a problem with the function running the above, and my model is logged out in the console but when i try to expand it its empty?
Its worth saying that neither success or error is being fired ont he 2nd route round.
Thanks
Edit #1
Here is the error i receive before the crash
<error>
w.extend
w.clone
e.extend.toJSON
_.extend.save
_.extend.update
LocalStorage.sync
Backbone.sync
e.extend.sync
e.extend.save
Evision.Views.TrackerDetail.Backbone.View.extend.saveTracker
(anonymous function)
j
Edit #2 Here is my model
Evision.Models.Track = Backbone.Model.extend({
defaults: function() {
return {
id : Evision.trackerList.nextOrder(),
completed : false,
created : Utils.datestamp(),
company : "",
revenue : "",
term : "",
comments : "",
probability : "",
success : null
}
}
});
I know exactly the problem. I had this issue not so long back. First thing I looked at was the stack trace and just like in the comments above I was getting an extend problem with underscore. What you need to do is update backbone.js, underscore.js and backbone-localstorage.js(if you have it) to the most recent versions. The problem lies with versioning!
Turns out the issue was related to a modified version of Jerome's Backbone.localStorage, which would allow for both remote and local storage within the app. I replaced with the latest localStorage adapter and everything is working fine. Unfortunately I cant find the original source to notify.

BackboneJS model.fetch() unsuccessful

Hi I have this model :
window.shop = Backbone.Model.extend({
initialize: function () {
console.log('initializing shop');
},
urlRoot: "shopData.json",
});
and then i go :
var myShop = new shop();
myShop.fetch({
success: function (model, resp){
console.log(resp);
},
error: function (model, resp){
console.log("error retrieving model");
}}, {wait: true});
now I'm always getting the error message - never reaching success :-(
thanks for any help.
Edit 1:
As per your comment the server is sending the proper response but Backbone is still calling the error function. Add the following line at the beginning of the error callback:
error: function (model, resp){
console.log('error arguments: ', arguments);
console.log("error retrieving model");
}
The first line should print an array of objects. The first element in the array should the jqXhr object, the second should be a string representation of the error. If you click on the first object, the dev tools will let you inspect its properties. Read up on the properties of the object here http://api.jquery.com/jQuery.ajax/#jqXHR.
Using that information you can verify if the jQuery is receiving an error from the server.
If there is no server side error, then check the value of the responseText property. That holds the string data returned from the server. $.ajax will try to parse that data into JSON. Most likely the parsing is throwing an error and the error handler is being raised instead.
Copy the response text and paste it into http://jsonlint.com/. Verify that the response sent from the server is valid JSON. Do update your question with the output of the console.log statement and the responseText property of the jqxhr object.
-x-x-x-
You seem to be using the model independently. As the per the documentation, http://backbonejs.org/#Model-url,
Generates URLs of the form: "/[urlRoot]/id"
That means, you are making a request to shopData.json/id. Also, you haven't specified the id.
Insert a console.log(myShop.url()) before the myShop.fetch(). Let us know whats the output. Also, possibly share the details of the ajax request as seen in Firebug or Chrome Dev Tools. I am interested in two things, the request url and the response returned by the server. (http://getfirebug.com/network)

Resources