I have been trying to create users on quickblox without any success. I have reviewed their documentation and have searched the internet, including SO, to no avail. Below is my code:
var QB = require('quickblox');
//Inizializing quickblox
QB.init(6455, "7j9XXXXXXXX", "DdWCXXXXXXX");
QB.createSession(function(err, result) {
// callback function
console.log('Callback', err, result);//This display 'Callback null undefine'
});
var params = { 'login': 'displayName', 'password': 'userIdert'};
QB.users.create(params, function(err, user) {
if (user)
{
console.log('Sign Up SUCCESS: ', JSON.stringify(user));
} else {
console.log('Sign Up ERROR: ', JSON.stringify(err));
}
});
PS:
I used this to install quickblox in nodejs: npm install quickblox --save
What I've tried
Tried to output the result gotten from createSession() it return null for error and undefine for result
Added QB.users.create() inside the callback function
Use qbuserparam with createSession()
Related
I am having trouble using the Parse Server JS SDK to edit and save a user.
I am signing in, logging in and retrieving the user just fine, I can call without exception user.set and add/edit any field I want, but when I try to save, even when using the masterKey, I get Error 206: Can t modify user <id>.
I also have tried to use save to direcly set the fields, same result.
A interesting thing is that in the DB, the User's Schema get updated with the new fields and types.
Here is my update function:
function login(user, callback) {
let username = user.email,
password = user.password;
Parse.User.logIn(username, password).then(
(user) => {
if(!user) {
callback('No user found');
} else {
callback(null, user);
}
},
(error) => {
callback(error.message, null);
}
);
}
function update(user, callback) {
login(user, (error, user) => {
if(error) {
callback('Can t find user');
} else {
console.log('save');
console.log('Session token: ' + user.getSessionToken());
console.log('Master key: ' + Parse.masterKey);
user.set('user', 'set');
user.save({key: 'test'}, {useMasterKey: true}).then(
(test) => {
console.log('OK - ' + test);
callback();
}, (err) => {
console.log('ERR - ' + require('util').inspect(err));
callback(error.message);
}
);
}
});
}
And a exemple of the error:
update
save
Session token: r:c29b35a48d144f146838638f6cbed091
Master key: <my master key>
ERR- ParseError { code: 206, message: 'cannot modify user NPubttVAYv' }
How can I save correctly my edited user?
I had the exact same problem when using Parse Server with migrated data from an existing app.
The app was created before March 2015 when the new Enhanced Sessions was introduced. The app was still using legacy session tokens and the migration to the new revocable sessions system was never made. Parse Server requires revocable sessions tokens and will fail when encountering legacy session tokens.
In the app settings panel, the Require revocable sessions setting was not enabled before the migration and users sessions were not migrated to the new system when switching to Parse Server. The result when trying to edit a user was a 400 Bad Request with the message cannot modify user xxxxx (Code: 206).
To fix the issue, I followed the Session Migration Tutorial provided by Parse which explain how to upgrade from legacy session tokens to revocable sessions. Multiple methods are described depending on your needs like enableRevocableSession() to enable these sessions on a mobile app, if you're only having a web app, you can enforce that any API requests with a legacy session token to return an invalid session token error, etc.
You should also check if you're handling invalid session token error correctly during the migration to prompt the user to login again and therefore obtain a new session token.
I had the same error and neither useMasterKey nor sessionToken worked for me either. :(
Here's my code:
console.log("### attempt 1 sessionToken: " + request.user.getSessionToken());
var p1 = plan.save();
var p2 = request.user.save(null, {sessionToken: request.user.getSessionToken()});
return Parse.Promise.when([p1, p2]).then(function(savedPlan) {
...
}
I see the matching session token in log output:
2016-08-21T00:19:03.318662+00:00 app[web.1]: ### attempt 1 sessionToken: r:506deaeecf8a0299c9a4678ccac47126
my user object has the correct ACL values:
"ACL":{"*":{"read":true},"PC7AuAVDLY":{"read":true,"write":true}}
I also see a bunch of beforeSave and afterSave logs with user being "undefined". not sure whether that's related.
beforeSave triggered for _User for user undefined:
I'm running latest parser-server version 2.2.18 on Heroku (tried it on AWS and results are the same)
function login(logInfo, callback) {
let username = logInfo.email,
password = logInfo.password;
Parse.User.logIn(username, password).then(
(user) => {
if(!user) {
callback('No user found');
} else {
callback(null, user);
}
},
(error) => {
callback(error.message, null);
}
);
}
function update(userInfo, data, callback) {
login(userInfo, (error, user) => {
if(error) {
callback('Can t find user');
} else {
getUpdatedData(user.get('data'), data, (error, updateData) => {
if(error) {
callback(error);
} else {
user.save({data: updateData}, /*{useMasterKey: true}*/ {sessionToken: user.get("sessionToken")}).then(
(test) => {
callback();
}, (err) => {
callback(error.message);
}
);
}
});
}
});
}
For some reason, retrying to use sessionToken worked.
This is not how asynchronous functions work in JavaScript. When createUser returns, the user has not yet been created. Calling user.save kicks off the save process, but it isn't finished until the success or error callback has been executed. You should have createUser take another callback as an argument, and call it from the user.save success callback.
Also, you can't create a user with save. You need to use Parse.User.signUp.
The function returns long before success or error is called.
I am using CollectionFS with GridFS to upload images:
Pictures.insert(e.target.files[0], function(err, res) {
if (err) return console.log(err);
this.setState({editing: false});
});
However when uploading I get an error:
Exception in delivering result of invoking '/cfs.pictures.filerecord/insert':
TypeError: Accounts._storedLoginToken is not a function
I've tried calling Accounts._storedLoginToken() in the Meteor shell and it gives the same error.
The error occurs here in the Meteor code:
var authToken = '';
if (typeof Accounts !== "undefined") {
var authObject = {
authToken: Accounts._storedLoginToken() || '',
};
// Set the authToken
var authString = JSON.stringify(authObject);
authToken = FS.Utility.btoa(authString);
}
Any help would be much appreciated.
Did you add accounts-base to your project? Accounts object does not have the _storedLoginToken method until you add a certain pkg such as account-base.
I am having trouble getting quickblox chat working on phonegap (javascript).I have used the revealing module pattern to expose instead of 'require' and this is the broken piece of code:
var chatParams = {
onConnectFailed: onConnectFailed,
onConnectSuccess: onConnectSuccess,
onConnectClosed: onConnectClosed,
onChatMessage: onChatMessage
};
QB.createSession(params, function(err, result) {
if (err==null) {
chatUser = {
id: result.user_id,
pass: params.password
};
connectChat(chatParams);
}
else {
alert("Something went wrong, please try again later or contact us at contact#domain.co.uk if the problem persists.");
}
});
function connectChat(chatParams) {
//This line here:
var chatService = new QBChat(chatParams);
console.log(chatService);
// connect to QB chat service
chatService.connect(chatUser);
};
I am getting the error 'object not a reference' at the highlighted line.
Please advise!
Try to use this code as an example to join chat:
QB.chat.connect({userId: user.id, password: user.pass}, function(err, roster) {
if (err) {
console.log(err);
} else {
console.log(roster);
}
});
instead of
function connectChat(chatParams) {
//This line here:
var chatService = new QBChat(chatParams);
console.log(chatService);
// connect to QB chat service
chatService.connect(chatUser);
};
I am new to rethinkdb.
When I try out the sample code in https://github.com/rethinkdb/rethinkdb-example-nodejs/tree/master/todo-angular-express
function create(req, res, next) {
var todo = req.body;
todo.createdAt = r.now(); // Set the field `createdAt` to the current time
r.table('todos').insert(todo, {returnVals: true}).run(req._rdbConn, function(error, result) {
if (error) {
handleError(res, error)
}
else if (result.inserted !== 1) {
handleError(res, new Error("Document was not inserted."))
}
else {
res.send(JSON.stringify(result.new_val));
}
next();
});
}
I got the following error:
500 Internal Server Error
{"error":"return_vals renamed to return_changes in:\nr.table(\"todos\").insert({title: r.json(\"\"abcde\"\"), completed: r.json(\"false\"), createdAt: r.now()}, {returnVals: true})\n
And then I tried out the sample code in http://rethinkdb.com/docs/examples/node-todo/
function create(req, res, next) {
var todo = req.body; // req.body was created by `bodyParser`
todo.createdAt = r.now(); // Set the field `createdAt` to the current time
r.table('todos').insert(todo, {returnChanges: true}).run(req._rdbConn, function(error, result) {
if (error) {
handleError(res, error)
}
else if (result.inserted !== 1) {
handleError(res, new Error("Document was not inserted."))
}
else {
res.send(JSON.stringify(result.changes[0].new_val));
}
next();
});
}
I got the following error:
500 Internal Server Error
{"error":"Unrecognized optional argument returnChanges. in:\nr.table(\"todos\").insert({title: r.json(\"\"abcde\"\"), completed: r.json(\"false\"), createdAt: r.now()}, {returnChanges: true})\n "}
It seems that rethinkdb have changed returnVals to return_changes / returnChanges, and the argument of insert().
And I have the problem fixed when I used return_changes.
What is the right way to work on insert in latest version?
Do rethinkdb always changes its syntax?
this is indeed a bug in the example code. I've opened https://github.com/rethinkdb/rethinkdb-example-nodejs/issues/3 so we can fix it.
Your second problem with returnChanges not being recognized might come from using an old RethinkDB node driver. Have you tried updating the driver? http://rethinkdb.com/docs/install-drivers/javascript/
I am trying to implement push notifications for my app using nodejs for the backend using quickblox. I'm following the steps to do that as mentioned on the quickblox site, i.e create a session user, create a push token, and last subscribe to notification channel. I'm facing a problem with the creation of the push token. My server side code looks like this:
app.post('/test_quickblox', function(req, res) {
var params = {
login: req.user.qb_username,
password: req.user.qb_password,
}
console.log(params);
QB.createSession(params, function(err, result) {
if (err) {
console.log(err);
}
console.log(result);
var options = {};
options.headers = {};
options.headers['QuickBlox-REST-API-Version'] = '0.1.0';
options.headers['QB-Token'] = result.token;
options.body = {};
options.body['push_token'] = {};
options.body['push_token']['environment'] = 'development';
options.body['push_token']['client_identification_sequence'] = '54b1e2b9e9081ed60520824054b1e2b8e9081ed60520823f';
options.body['device'] = {};
options.body['device']['platform'] = 'ios';
options.body['device']['udid'] = 'e0101010d38bde8e6740011221af335301010333';
options.url = 'http://api.quickblox.com/push_tokens.json';
QuickbloxRequest(options, function(err, response) {
if (err) {
console.log(err);
return apiError();
}
console.log(response);
res.apiSuccess();
});
});
});
when logging the response it looks like the following
{ _id: '54b1e3a1535c121c2000be66',
application_id: 18113,
created_at: '2015-01-11T02:44:49Z',
device_id: 0,
nonce: 8394,
token: 'bf61098a35fac9389be236caec44f0a9827630d1',
ts: 1420944288,
updated_at: '2015-01-11T02:44:49Z',
user_id: 2179940,
id: 56046 }
and the error I get is:
{"code":null,"message":"No device registered for current user session. Device is obligatory to be able to execute actions with push token."}
I guess the problem lies in the device_id being 0.
Note that I am creating the users in another controller without supplying any device_id upon creation, so I think that might be my problem but I am new to quickblox and do not understand yet all the semantics so please help me find out what the problem is. Thanks
And here we are 4 years later and I faced the same problem. No answer, no nothing, it makes you wonder how large is the quickblox community :O
Anyway, for anyone coming here with the same problem : It seems the problem is that the Android UUID returned by PhoneGap is too short so quickblox rejects it silently.
Here is what worked for me. Pay attention to the doubling of the uuid :
window.device.uuid + window.device.uuid
JS Code :
//REGISTER AS ANDROID
var message = {
environment: "development",
client_identification_sequence: e.regid,
platform: "android",
udid: window.device.uuid + window.device.uuid,
};
if (BBPushNotification.showLog) console.log(message);
QB.messages.tokens.create(message, function(err, response){
if (err) {
if (BBPushNotification.showLog) console.log("Create token error : ",err);
} else {
if (BBPushNotification.showLog) console.log("Create token success : ",response);
}
});