Hi, before upgrading to v23, i passed the withCredentials property inside the beforeSend function in a class that extended ODataV4Adaptor:
however, after upgranding packages to v23, has an error inside the function
the message error is:
I was expecting Request, but you passed XMLHttpRequest.
And when I change the typing to Request, there is no property called withCredentials. So how can I pass this property after upgrading to v23?
Hi Rellyson
In our latest DataManager(v23), we are
using fetch request instead of our default AJAX library (which
uses XMLHttpRequest). For AJAX, we can enable cookies in the browser by setting
"withCredentials" to true in the Datamanager’s beforeSend() method.
For Fetch, we can enable cookies by setting “credentials” as include. However,
when using fetch requests, we cannot directly set the “credentials” as
“include” in the beforeSend() method.
Because the credentials property of a fetch request is initially set to read-only, so if you want to enable cookies, you can override the beforeSend() method and generate a new fetch request to set the credentials as include to achieve your requirement. Please refer the below code example for more for information.
|
export class DataManagerAdaptor extends OdataV4Adaptor { public beforeSend (args, xhr, settings): void { //inside beforeSend here you have create a new Request and set credentials as include var newFetchRequest = new Request(settings.url, { method: settings.fetchRequest.method, headers: { 'Syncfusion': true}, credentials: 'include', // Set credentials to 'include' here }); settings.fetchRequest = newFetchRequest;
} }
|
Regards,
Joseph I.
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Hello,
and how does it work for URLAdaptor that does not use Settings?
Lukas
Hi Lukas Kubaliak,
Thank you for reaching out to us.
If you wish to include headers, you can do so directly. However, if you want to enable cookies, setting the "credentials" as "include" in the beforeSend() method is not possible.
To achieve this, you can override the beforeSend() method and create a new fetch request with the credentials set as include. Additionally, it is essential to specify the content format on your end.
Please refer to the below code snippet for more information.
Code sample :
|
beforeSend (args, xhr, settings, request){ var newFetchRequest = new Request(settings.url, { method: settings.fetchRequest.method, headers: { 'Syncfusion': true, 'Content-Type': '*'}, credentials: 'include', }); settings.fetchRequest = newFetchRequest; }
|
Please get back to us, if you need further assistance.
Regards,
Johnson Soundararajan S