Only set XHR authorization header if token isn't empty

This commit is contained in:
Toby Zerner
2015-09-14 14:49:11 +09:30
parent f00d2b1363
commit d5b58b3146

View File

@ -16,6 +16,7 @@ export default class Session {
* The token that was used for authentication. * The token that was used for authentication.
* *
* @type {String|null} * @type {String|null}
* @public
*/ */
this.token = token; this.token = token;
} }
@ -26,6 +27,7 @@ export default class Session {
* @param {String} identification The username/email. * @param {String} identification The username/email.
* @param {String} password * @param {String} password
* @return {Promise} * @return {Promise}
* @public
*/ */
login(identification, password) { login(identification, password) {
return app.request({ return app.request({
@ -38,6 +40,8 @@ export default class Session {
/** /**
* Log the user out. * Log the user out.
*
* @public
*/ */
logout() { logout() {
window.location = app.forum.attribute('baseUrl') + '/logout?token=' + this.token; window.location = app.forum.attribute('baseUrl') + '/logout?token=' + this.token;
@ -48,8 +52,11 @@ export default class Session {
* XMLHttpRequest object. * XMLHttpRequest object.
* *
* @param {XMLHttpRequest} xhr * @param {XMLHttpRequest} xhr
* @public
*/ */
authorize(xhr) { authorize(xhr) {
if (this.token) {
xhr.setRequestHeader('Authorization', 'Token ' + this.token); xhr.setRequestHeader('Authorization', 'Token ' + this.token);
} }
}
} }