Skip to content

Commit

Permalink
DRYD-1242: Fix unnecessary re-authorization. (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-lee authored Oct 2, 2023
1 parent 3eec4c0 commit 20d0f92
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cspace-ui",
"version": "9.0.0-dev.2",
"version": "9.0.0-dev.3",
"description": "CollectionSpace user interface for browsers",
"author": "Ray Lee <[email protected]>",
"license": "ECL-2.0",
Expand Down
3 changes: 3 additions & 0 deletions src/actions/cspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const setSession = (newSession) => {
return {
type: CSPACE_CONFIGURED,
payload: getSession().config(),
meta: {
username: getSession().username(),
},
};
};

Expand Down
5 changes: 3 additions & 2 deletions src/actions/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,15 @@ export const login = (config, authCode, authCodeRequestData = {}) => (dispatch,
};

/**
* Log in using a fulfilled authorization code request.
* Receive an authorization code from the OAuth server. This will have been sent in a redirect from
* the server, in response to an authorization code request.
*
* @param {*} config
* @param {*} authCodeRequestId
* @param {*} authCode
* @returns
*/
export const loginWithAuthCodeRequest = (
export const receiveAuthCode = (
config,
authCodeRequestId,
authCode,
Expand Down
6 changes: 3 additions & 3 deletions src/components/pages/AuthorizedPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const propTypes = {
location: PropTypes.shape({
search: PropTypes.string,
}).isRequired,
loginWithAuthCodeRequest: PropTypes.func.isRequired,
receiveAuthCode: PropTypes.func.isRequired,
username: PropTypes.string,
};

Expand Down Expand Up @@ -167,7 +167,7 @@ export default function AuthorizedPage(props, context = {}) {
isPending,
isSuccess,
location,
loginWithAuthCodeRequest,
receiveAuthCode,
username,
} = props;

Expand All @@ -180,7 +180,7 @@ export default function AuthorizedPage(props, context = {}) {
const authCodeRequestId = params.get('state');
const authCode = params.get('code');

loginWithAuthCodeRequest(config, authCodeRequestId, authCode);
receiveAuthCode(config, authCodeRequestId, authCode);
}, []);

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/containers/pages/AuthorizedPageContainer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import AuthorizedPage from '../../components/pages/AuthorizedPage';
import { loginWithAuthCodeRequest } from '../../actions/login';
import { receiveAuthCode } from '../../actions/login';

import {
getLoginUsername,
Expand All @@ -19,7 +19,7 @@ const mapStateToProps = (state) => ({
});

const mapDispatchToProps = {
loginWithAuthCodeRequest,
receiveAuthCode,
};

export default connect(
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default (state = Immutable.Map(), action) => {
case AUTH_RENEW_FULFILLED:
return handleAccountPermsReadFulfilled(state, action);
case CSPACE_CONFIGURED:
return state.set('username', action.payload.username);
return state.set('username', action.meta.username);
case LOGIN_FULFILLED:
return state.set('username', action.meta.username);
case LOGOUT_FULFILLED:
Expand Down
3 changes: 2 additions & 1 deletion test/specs/reducers/user.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ describe('user reducer', () => {

const state = reducer(undefined, {
type: CSPACE_CONFIGURED,
payload: {
payload: {},
meta: {
username,
},
});
Expand Down

0 comments on commit 20d0f92

Please sign in to comment.