Skip to content

Commit

Permalink
Merge pull request #151 from dekart-xyz/fix-auth-error-infinite-loop
Browse files Browse the repository at this point in the history
Fix auth error infinite loop
  • Loading branch information
delfrrr authored Dec 6, 2023
2 parents 95f97b6 + 1a61905 commit 5b2d9a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/client/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function AppRedirect () {
}, [status, doNotAuthenticate])

if (status === 401 && doNotAuthenticate === false) {
// redirect to authentication endpoint from useEffect
return null
}

Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export function setError (err, transitive = true) {
}
}

export function setHttpError (status, message = '', doNotAuthenticate = false) {
return { type: setHttpError.name, status, message, doNotAuthenticate }
export function setHttpError (status, message = '') {
return { type: setHttpError.name, status, message}
}

export function setStreamError (code, msg) {
Expand Down
16 changes: 11 additions & 5 deletions src/client/reducers/rootReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,18 @@ function env (state = defaultEnv, action) {

function httpError (state = {}, action) {
switch (action.type) {
case setHttpError.name:
return {
status: action.status,
message: action.message,
doNotAuthenticate: action.doNotAuthenticate
case setHttpError.name: {
if (action.status === 401 && state.doNotAuthenticate) {
// just keep showing auth error, do not override it with other 401
return state
} else {
return {
status: action.status,
message: action.message,
doNotAuthenticate: false
}
}
}
case setRedirectState.name: {
const err = action.redirectState.getError()
if (err) {
Expand Down

0 comments on commit 5b2d9a7

Please sign in to comment.