mirror of https://github.com/zulip/zulip.git
ts: Convert csrf module to TypeScript.
This commit is contained in:
parent
35738e148b
commit
a8cdc968cc
|
@ -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);
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue