Skip to content

Instantly share code, notes, and snippets.

@mariojunior
Created August 7, 2013 16:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mariojunior/6175849 to your computer and use it in GitHub Desktop.
Save mariojunior/6175849 to your computer and use it in GitHub Desktop.
AngularJS Learned Lessons #2: Enabling HTTP Credentials (needed by Session IDs)
//On config definition...
angular.module("moduleName").config(
function ($routeProvider, $httpProvider) {
//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