ts: Convert csrf module to TypeScript.

This commit is contained in:
Priyank Patel 2021-06-13 23:34:32 +00:00 committed by Tim Abbott
parent 35738e148b
commit a8cdc968cc
2 changed files with 7 additions and 3 deletions

View File

@ -1,6 +1,6 @@
import $ from "jquery";
export let csrf_token;
export let csrf_token: string | undefined;
$(() => {
// This requires that we used Jinja2's {% csrf_input %} somewhere on the page.
@ -11,7 +11,11 @@ $(() => {
}
$.ajaxSetup({
beforeSend(xhr, settings) {
beforeSend(xhr: JQuery.jqXHR, settings: JQuery.AjaxSettings) {
if (settings.url === undefined || csrf_token === undefined) {
throw new Error("settings.url and/or csrf_token are missing.");
}
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
// Only send the token to relative URLs i.e. locally.
xhr.setRequestHeader("X-CSRFToken", csrf_token);

View File

@ -53,7 +53,7 @@ EXEMPT_FILES = {
"static/js/condense.js",
"static/js/confirm_dialog.js",
"static/js/copy_and_paste.js",
"static/js/csrf.js",
"static/js/csrf.ts",
"static/js/css_variables.js",
"static/js/debug.js",
"static/js/deprecated_feature_notice.js",