25 lines
562 B
JavaScript
25 lines
562 B
JavaScript
|
#include utility.js
|
||
|
|
||
|
const MszCSRF = (() => {
|
||
|
let elem;
|
||
|
const getElement = () => {
|
||
|
if(elem === undefined)
|
||
|
elem = $q('meta[name="csrf-token"]');
|
||
|
return elem;
|
||
|
};
|
||
|
|
||
|
return {
|
||
|
get token() {
|
||
|
return getElement()?.content ?? '';
|
||
|
},
|
||
|
set token(token) {
|
||
|
if(typeof token !== 'string')
|
||
|
throw 'token must be a string';
|
||
|
|
||
|
const elem = getElement();
|
||
|
if(elem instanceof HTMLMetaElement)
|
||
|
elem.content = token;
|
||
|
},
|
||
|
};
|
||
|
})();
|