Skip to content

Commit 7a4505f

Browse files
RaubzeugCopilot
andauthored
feat: add support for csrf (#2604)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent dcbefa1 commit 7a4505f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/services/api/index.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export class YdbEmbeddedAPI {
2727
meta?: MetaAPI;
2828
codeAssist?: CodeAssistAPI;
2929

30-
constructor({webVersion = false, withCredentials = false} = {}) {
30+
constructor({
31+
webVersion = false,
32+
withCredentials = false,
33+
csrfTokenGetter = () => undefined,
34+
} = {}) {
3135
const config: AxiosRequestConfig = {withCredentials};
3236

3337
this.auth = new AuthAPI({config});
@@ -47,5 +51,22 @@ export class YdbEmbeddedAPI {
4751
this.tablets = new TabletsAPI({config});
4852
this.vdisk = new VDiskAPI({config});
4953
this.viewer = new ViewerAPI({config});
54+
55+
const token = csrfTokenGetter();
56+
if (token) {
57+
this.auth.setCSRFToken(token);
58+
// Use optional chaining as `meta` may not be initialized.
59+
this.meta?.setCSRFToken(token);
60+
// Use optional chaining as `codeAssist` may not be initialized.
61+
this.codeAssist?.setCSRFToken(token);
62+
this.operation.setCSRFToken(token);
63+
this.pdisk.setCSRFToken(token);
64+
this.scheme.setCSRFToken(token);
65+
this.storage.setCSRFToken(token);
66+
this.streaming.setCSRFToken(token);
67+
this.tablets.setCSRFToken(token);
68+
this.vdisk.setCSRFToken(token);
69+
this.viewer.setCSRFToken(token);
70+
}
5071
}
5172
}

0 commit comments

Comments
 (0)