mirror of
https://github.com/flarum/framework.git
synced 2025-05-23 07:09:57 +08:00
Only set XHR authorization header if token isn't empty
This commit is contained in:
@ -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) {
|
||||||
xhr.setRequestHeader('Authorization', 'Token ' + this.token);
|
if (this.token) {
|
||||||
|
xhr.setRequestHeader('Authorization', 'Token ' + this.token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user