Use withCredential with $ resource

I want to use a cookie set resource in the navigator.

With $ http, this is very simple since I only need to set withCredential to true:

$http({ method: 'POST', url: url, data: user, withCredentials: true }); 

But for $ resource, I did not find a solution to arrange the same ... I saw a discussion on github about this, but I think that setting withCredential to true for all requests is out of order. Do you have an idea on how to do this?

+6
source share
3 answers

The configuration withCredentials in $ resource is available in AngularJS 1.1.2+, you can get a new version and try it.

+6
source

To change the default settings of $http (hence $ resource), you need to change $httpProvider .

Install withCredentials globally:

 angular.module('YOUR_APP') .config(function($httpProvider) { $httpProvider.defaults.withCredentials = true; }); 
+14
source

You can set the flag all over the world:

  $http.defaults.withCredentials = true; 

This will affect all requests for the $resource module, as well as the $http module.

+3
source

Source: https://habr.com/ru/post/952932/


All Articles