Closed sabsaxo closed 6 years ago
When I console.log the instance, I can see the cookies just fine, and $persistentcookies
are set to true:
RESTBuilder {
'$url': 'http://localhost:8000/main/api/constants/',
'$headers':
{ 'user-agent': 'Total.js/v2.9.4',
accept: 'application/json, text/plain, text/plain, text/xml' },
'$method': 'get',
'$timeout': 10000,
'$type': 0,
'$length': 0,
'$transform': undefined,
'$files': null,
'$persistentcookies': true,
'$cookies':
{ csrftoken: 'xunv27vWsPgl8xp7q2E7UcKYIJiESIKk',
sessionid: '0bhtap9p9v9esfmw55lumy2kqfi6jqdi'
},
'$flags': [ 'get', 'dnscache', 'cookies' ]
}
Try this:
var cookies = {};
F.helpers.getConstants = function ( callback ) {
let constants = {};
RESTBuilder.make(function ( builder ) {
builder.cookies( cookies );
builder.cook( true );
builder.exec(function ( err, response, output ) {
console.log("Cookies:", cookies );
/**
* Outputs:
* Cookies: { csrftoken: '8Cn3at5n9oW1CgxrXmbrELIxjdpDAGYj',
* sessionid: 'dseh0llwjhi8hk7rfix38igi7s648fy1' }
*/
if ( callback ) {
callback( constants );
}
});
});
};
RESTBuilder.make(function ( builder ) {
creates a new instance of RESTBuilder, so it's useless to set builder.cookie()
after you perform .exec()
.
Same result, no cookies set.
OK, then I totally do not understand that part of the framework. Where would I centrally place a cookie that will update on a call that gets made everytime a csrftoken is renewed?
And how can I then avoid to create new instance everytime? The url doesn't change, so I guess the instance doesn't need to neither.
So, what is happening here? Are the cookies reset after .exec() ... or what are you saying?
I request the node server for a login form. When submitting the form I request a Django backend on another server, and I need to make cookies persist across the two servers.
I can do that when I set the cookies from the controller and adding 'withCredentials' : true to my xhr, but I'd like to avoid to have to set them in each and every controller method across the whole application ... so, what I'm after is a 'structure' for how to make this a central thing in the request chain.
So, what is happening here? Are the cookies reset after .exec() ... or what are you saying?
No. All is about reference to cookie object. RESTBuilder
binds received cookies after .exec
. I wrote you about it in Total.js messenger. As I said: I help you within Total.js support.
I've been trying for a long time to set a cookie from a RESTBuilder instance (placed in a definition) using:
I'm only able to set them back in the calling controller, passing the values back from the helper. But I'd really like to be able to set this in a central place, so I don't have to place controller.cookie( ... ) all over my controllers.
Am I doing it wrong (missing the point), or is this a bug?