-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from dekart-xyz/oss-fix-error-wher-requesting…
…-auth Oss fix error wher requesting auth
- Loading branch information
Showing
10 changed files
with
80 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
export function setRedirectState (redirectState) { | ||
return { type: setRedirectState.name, redirectState } | ||
} | ||
|
||
const { REACT_APP_API_HOST } = process.env // this never changes, passed during build | ||
|
||
// authRedirect will redirect the browser to the authentication endpoint | ||
export function authRedirect (state) { | ||
return async (dispatch) => { | ||
dispatch({ type: authRedirect.name }) | ||
const req = new URL('/api/v1/authenticate', REACT_APP_API_HOST || window.location.href) | ||
state.setAuthUrl(req.href) | ||
const stateBase64 = btoa(String.fromCharCode.apply(null, state.serializeBinary())) | ||
req.searchParams.set('state', stateBase64) | ||
window.location.href = req.href | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { setHttpError } from '../actions/message' | ||
import { authRedirect, setRedirectState } from '../actions/redirect' | ||
|
||
export default function httpError (state = {}, action) { | ||
switch (action.type) { | ||
case setHttpError.name: { | ||
if (action.status === 401 && state.doNotAuthenticate) { | ||
// just keep showing auth error, do not override it with other 401 | ||
return state | ||
} else if (state.redirecting) { | ||
// do nothing as page is getting redirected and requests are getting cancelled | ||
return state | ||
} else { | ||
return { | ||
status: action.status, | ||
message: action.message, | ||
doNotAuthenticate: false | ||
} | ||
} | ||
} | ||
case authRedirect.name: { | ||
return { | ||
...state, | ||
redirecting: true | ||
} | ||
} | ||
case setRedirectState.name: { | ||
const err = action.redirectState.getError() | ||
if (err) { | ||
return { | ||
status: 401, | ||
message: err, | ||
doNotAuthenticate: true | ||
} | ||
} else { | ||
return {} // reset error | ||
} | ||
} | ||
default: | ||
return state | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters