Skip to content

Commit

Permalink
Fixes issue where calls to the /settings endpoint fails due to bein…
Browse files Browse the repository at this point in the history
…g called before SSO / PKCE libraries are initialized. (#2723)
  • Loading branch information
kevgliss authored Nov 23, 2022
1 parent 3e51e47 commit 4916b86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/dispatch/static/dispatch/src/app/store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getField, updateField } from "vuex-map-fields"
import router from "@/router"

const getDefaulRefreshState = () => {
const getDefaultRefreshState = () => {
return {
show: false,
message: "",
Expand All @@ -11,7 +11,7 @@ const getDefaulRefreshState = () => {
const state = {
toggleDrawer: true,
refresh: {
...getDefaulRefreshState(),
...getDefaultRefreshState(),
},
loading: false,
}
Expand Down Expand Up @@ -46,7 +46,7 @@ const mutations = {
state.loading = value
},
RESET_REFRESH(state) {
state.refresh = Object.assign(state.refresh, getDefaulRefreshState())
state.refresh = Object.assign(state.refresh, getDefaultRefreshState())
},
}

Expand Down
18 changes: 13 additions & 5 deletions src/dispatch/static/dispatch/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ import VueMarkdown from "vue-markdown"

// initialize the app settings before mounting the app
function initialize() {
return axios.get("/api/v1/settings").then((response) => {
for (const [key, value] of Object.entries(response.data)) {
localStorage.setItem(key, value)
}
})
// Only attempt to setup app context on full page / app reload. This is needed because
// SSO providers will likely protect the /api/v1/settings endpoint _before_ we can initialize the SSO
// libraries. On full app load the SSO flow will executed for the static files themselves and this call will succeed.
//
// On simple page refresh this is not always the case so we re-use the existing settings and do not attempt to fetch them.

if (!localStorage.getItem("DISPATCH_AUTHENTICATION_PROVIDER_SLUG")) {
return axios.get("/api/v1/settings").then((response) => {
for (const [key, value] of Object.entries(response.data)) {
localStorage.setItem(key, value)
}
})
}
}

initialize().then(() => {
Expand Down

0 comments on commit 4916b86

Please sign in to comment.