-
-
Save andrewdelprete/10021594 to your computer and use it in GitHub Desktop.
Angular Cookie Fix - Standard CORS requests do not send or set any cookies by default : withCredentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//On config definition... | |
angular.module("moduleName").config( | |
function ($routeProvider, $httpProvider) { | |
// ALLOWS CORS | |
// Standard CORS requests do not send or set any cookies by default. In order to include cookies as | |
// part of the request, you need withCredentials property to true. | |
// http://www.html5rocks.com/en/tutorials/cors/ | |
// HERE THE IMPORTANT MAGIC LINE! | |
$httpProvider.defaults.withCredentials = true; | |
//If you don't set the line above, all $http will dispatch request without session_id to backend | |
//and the backend will not reconize the user session, giving your a big head pain! Believe on me. | |
//Question & Answer: http://stackoverflow.com/questions/17064791/http-doesnt-send-cookie-in-requests | |
//continue the configuration setting your routing definitions... blablabla... | |
$routeProvider | |
//Index and global pages | |
.when('/', { controller: IndexCtrl, templateUrl: TEMPLATE_DIR + 'main/login.html' }) | |
//.... set your routings definitions... | |
.otherwise({redirectTo: '/notFound'}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment