Skip to content

Instantly share code, notes, and snippets.

@andrewdelprete
Forked from mariojunior/gist:6175849
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewdelprete/10021594 to your computer and use it in GitHub Desktop.
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
//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