Skip to content

Commit

Permalink
feat: before 0.13.0 release changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-cucu committed Sep 27, 2024
1 parent 4ab9252 commit cbec72b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/juju/jimm/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const jimmEndpoint =
window.jujuDashboardConfig?.controllerAPIEndpoint
.replace("wss://", "https://")
.replace("ws://", "http://")
.replace(/\/api$/, "") ?? "";

export const endpoints = {
login: "/auth/login",
logout: "/auth/logout",
whoami: "/auth/whoami",
login: `${jimmEndpoint}/auth/login`,
logout: `${jimmEndpoint}/auth/logout`,
whoami: `${jimmEndpoint}/auth/whoami`,
};
4 changes: 3 additions & 1 deletion src/juju/jimm/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const addWhoamiListener = (
try {
while (true) {
await forkApi.delay(OIDC_POLL_INTERVAL);
const response = await forkApi.pause(fetch(endpoints.whoami));
const response = await forkApi.pause(
fetch(endpoints.whoami, { credentials: "include" }),
);
// Handle the user no longer logged in:
if (response.status === 401 || response.status === 403) {
throw new Error(Label.ERROR_LOGGED_OUT);
Expand Down
4 changes: 2 additions & 2 deletions src/juju/jimm/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const logout = createAsyncThunk<
}
>("jimm/logout", async () => {
try {
const response = await fetch(endpoints.logout);
const response = await fetch(endpoints.logout, { credentials: "include" });
if (!response.ok) {
throw new Error("non-success response");
}
Expand All @@ -37,7 +37,7 @@ export const whoami = createAsyncThunk<
}
>("jimm/whoami", async () => {
try {
const response = await fetch(endpoints.whoami);
const response = await fetch(endpoints.whoami, { credentials: "include" });
if (response.status === 401 || response.status === 403) {
// The user is not authenticated so return null instead of throwing an error.
return null;
Expand Down

0 comments on commit cbec72b

Please sign in to comment.