After I create a new BrowserWindow I launch this code on its webContents
newRoom.webContents.executeJavaScript(
client.emit("authentication", {
username: "bob",
password: "1234"
})
);
The code executes fine but I'm getting an error thrown in devtools -
Uncaught (in promise) TypeError: Error processing argument at index 1, conversion failure from #<Object>
Is there something wrong perhaps with the formatting of the code ?
As usual, reading the documentation is probably the first and best thing to do...
The webContents method contents.executeJavaScript is expecting a string of code as first argument...
This could do the trick:
newRoom.webContents.executeJavaScript(
'client.emit("authentication", { username: "bob", password: "1234" })'
);
or:
newRoom.webContents.executeJavaScript(
`client.emit("authentication", {
username: "bob",
password: "1234"
})`
);
However, the original question mentions that "the code executes fine", which would mean that it doesn't even need to be passed to the renderer process to get executed...
client.emit("authentication", {
username: "bob",
password: "1234"
});
Related
I have an IOT device, its coded in Lua, I didn't do that part of the project, so I don't know much about it.
I have 2 almost identical axios posts.
run via an app
await axios.post(url,{ cmd:'{"cmd": {"uuid":"'+serial+'","name":"RR","value":"'+key+'"}}' } , { auth: { username: 'admin', password: 'rLVeGRk9ezWj' } }
run via a local HTML page to test:
const body = { cmd:'{"cmd": {"uuid":"'+serial+'","name":"RR","value":"'+key+'"}}' }
const resp2 = await axios.post(url, body, { auth: { username: 'admin', password: 'rLVeGRk9ezWj' })
In the lua side, the HTML example works perfectly. My app version (#1 above), actually sends twice. Causes a "Ignoring new incoming data. Failed to get header".
I compared headers, content-length and looks identical.
To anyone else experiencing this, the Lua device was splitting the data when it was too long. The IOT developer had to make a change to handle long posts
I'm trying to use GraphQL in iOS with Apollo Client. I have the following mutation:
login(user: String!, password: String!): UserType
and the UserType looks like this:
id: ID
user: String!
password: String!
name: String
lastname: String
email: Email!
groups: [GroupType]
In iOS, I have configured aopllo client as the doc says and is working perfectly, but I don't know how to get access to every field in the response. When the login success I want to read the json I receive as response with the UserType fields, so, I'm doing this:
apolloClient.perform(mutation: loginMutation) {
resultsGQL, error in
...
}
My question is, how can I read every field from resultGQL which belongs to the UserType data defined in my grapql schema?
Regards
The question is not 100% clear, since it is missing some code your mutation: A GraphQL mutation has to return at least one value, which you have to define. Since i'm not sure about your method
login(user: String!, password: String!): UserType
i am giving you a simple example for updating an existing userProfile with a GraphQL mutation and then returning every field being defined in your schema for userType.
Let us assume you have a userType (and therefore know the corresponding userId) and you want to modify the email:
mutation updateUserProfile($id: ID!, $newEmail: String) {
updateUser(id: $id, email: $newEmail) {
id
user
password
name
lastName
email
}
}
As you can see, after executing
updateUser(id: $id, email: $newEmail)
all return values are defined inside the following {...} parentheses and are therefore accessible in your callback variable
resultsGQL
That means:
apolloClient.perform(mutation: loginMutation) { resultsGQL, error in
if let results = resultsGQL?.data {
// "results" can now access all data from userType
}
}
Since you defined all entities of your userType schema to be returned from the mutation, you can access them now in your callback variable.
I'm using simple-oauth2. I've got the authorization part working, and I'm getting a code back from the API. However, when I attempt to create a token from that code using simple-oauth2's authCode.getToken function, the result is blank.
oauth2.authCode.getToken({
code: code,
redirect_uri: credentials.redirect_uri
}, callback);
function callback(err, result){
console.log(result)
token = oauth2.accessToken.create(result);
}
That console.log statement returns absolutely nothing, not even "undefined." Tokens created with this blank result have an empty string as the "token" property inside the returned object, like so:
{ create: [Function: create],
token: '',
expired: [Function: expired],
refresh: [Function: refresh],
revoke: [Function: revoke] }
This code is copied nearly verbatim from the examples page, and I can't figure out what I could be doing wrong. What am I missing?
It turns out my config.site URL just had http, not https, and so wasn't returning anything. Adding the "s" fixed it.
I'm new to using restangular. With that said, I have the below POST call which for some reason is not working as expected.
Restangular.all("user").all("login").post({username: 'test#user.com', password: 'xyz'}).then(function(account)
{
console.log(account);
});
I see the POST request going out to the url /api/v1/user/login which is the correct url. However, the post parameters don't appear to be getting passed. Looking at that same POST request I don't see the username/password data. In addition, my API is throwing an unauthorized error which says to me it is unable to validate the user based on credentials.
I have also tried variants as follows...
Restangular.one("user").post("login", {username: 'test#user.com', password: 'xyz'}).then(function(account)
{
console.log(account);
})
Still the post data doesn't appear to be getting sent. I have also tried...
Restangular.all("user").post("login", {username: 'test#user.com', password: 'xyz'}).then(function(account)
{
console.log(account);
})
That appears to create an incorrect url /api/v1/user and no post data is still not visible.
I can perform cURL POST requests to /api/v1/user/login passing in the POST data without issue.
cURL -X POST /api/v1/user/login -d "username=test#user.com&password=xyz"
I also updated my curl statement as #David suggested in his answer to...
curl -X POST -d '{"username": "test#user.com", "password": "xyz"}' '/api/v1/user/login' -H Content-Type:application/json
Which still worked. However, posting with restangular doesn't...
Restangular.all("user").post("login", {username: 'test#user.com', password: 'xyz'}).then(function(account)
{
console.log(account);
})
Additional ideas?
I'm not an expert in Restangular but it seems .all() creates a full set of REST APIs for an object. In this case I think you only want to call .all() on "user" and use login as a subresource.
var users = Restangular.all("user");
users.post('login', {
username: 'test#user.com',
password: 'xyz'
}).then(...);
Also you need to make sure your server actually has a POST /users/login endpoint.
I see that's one year old question but anyway. I have faced the same issue and I bielive I found solution for this problem. The all thing is in Restangular.setRequestInterceptor event. So if you have a such interceptor in your code then you need to be sure that it returns accepted element parameter after your required actions was made. For example that's what I had before:
Restangular.setRequestInterceptor(function () {
$rootScope.validationErrors = [];
activeRequests++;
$rootScope.loading = true;
})
And that's what should be done with it:
Restangular.setRequestInterceptor(function (element, operation, what, url) {
$rootScope.validationErrors = [];
activeRequests++;
$rootScope.loading = true;
return element;
})
You are sending incorrectly the post params, you have:
Restangular.all("user").all("login")
.post({username: 'test#user.com', password: 'xyz'})
.then(function(account) {
console.log(account);
});
So, you need to make a little change and it will be works (send body params correctly):
Restangular.all("user").all("login")
.post('', {username: 'test#user.com', password: 'xyz'})
.then(function(account) {
console.log(account);
});
Note: I tried it on restangular v1.5.2
Good luck!
I'm trying to bind an attribute of a DS.belongsTo relationship like this:
App.User = DS.Model.extend({
name: DS.attr('string')
});
App.Post = DS.Model.extend({
text: DS.attr('string'),
user: DS.belongsTo('App.User'),
userNameBinding: 'user.name'
});
I know this example is a little bit stupid, but the idea is here.
Unfortunately, it does not work (in model.js, at this line):
Uncaught TypeError: Cannot call method 'send' of null
I also tried to use Ember.Binding.oneWay, but it does not work either. My current workaround is pretty ugly:
App.Post = DS.Model.extend({
// code omitted
userName: function() {
return this.get('user.name');
}.property('user.name')
});
You can test it in this JSFiddle.
Ember version used:
ember-data on master
ember v1.0.0-pre.2-311-g668783a
There appears to be a bug with bindings to properties that rely on state set up in init. I have filed a bug on the Ember issue tracker.
For a less ugly solution, you can use Ember.computed.alias:
App.Post = DS.Model.extend({
text: DS.attr('string'),
user: DS.belongsTo('App.User'),
userName: Ember.computed.alias('user.name')
});
I have a working example in this JSBin.