Skip to content

Commit aeeb3dc

Browse files
committed
Include credentials in update check fetch request
This allows the update check endpoint to authenticate the request using session cookies, enabling protected update check endpoints. (cherry picked from commit d3173fe)
1 parent d4bd361 commit aeeb3dc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

app/javascript/alchemy_admin/components/update_check.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class UpdateCheck extends HTMLElement {
66
spinner.spin(this)
77

88
try {
9-
const response = await fetch(this.url)
9+
const response = await fetch(this.url, { credentials: "include" })
1010
const responseJSON = await response.json()
1111

1212
if (response.ok) {

spec/javascript/alchemy_admin/components/update_check.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ describe("alchemy-update-check", () => {
2727
vi.clearAllMocks()
2828
})
2929

30+
it("fetches with credentials included", async () => {
31+
global.fetch.mockResolvedValueOnce({
32+
ok: true,
33+
json: () => Promise.resolve({ status: "true" })
34+
})
35+
36+
component = renderComponent("alchemy-update-check", html)
37+
await new Promise(process.nextTick)
38+
39+
expect(global.fetch).toHaveBeenCalledWith("/update_check", {
40+
credentials: "include"
41+
})
42+
})
43+
3044
it("shows update available when response is 'true'", async () => {
3145
global.fetch.mockResolvedValueOnce({
3246
ok: true,

0 commit comments

Comments
 (0)