Skip to content

Commit

Permalink
Updating Login component to POST to new config.loginUrl.
Browse files Browse the repository at this point in the history
  • Loading branch information
erinesullivan committed Aug 18, 2023
1 parent 9a6d9ea commit 9b0d4f8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"eject": "react-scripts eject",
"lint": "npx eslint src/**/*.js",
"reinstall": "rm -rf node_modules && npm install",
"start": "REACT_APP_SPECTRUM_BASE_URL=${REACT_APP_SPECTRUM_BASE_URL:-https://search-staging.www.lib.umich.edu/spectrum} react-scripts start",
"start": "REACT_APP_SPECTRUM_BASE_URL=${REACT_APP_SPECTRUM_BASE_URL:-https://search-staging.www.lib.umich.edu/spectrum} REACT_APP_LOGIN_BASE_URL=${REACT_APP_LOGIN_BASE_URL:-https://search-staging.www.lib.umich.edu} react-scripts start",
"test": "react-scripts test --env=jsdom"
},
"browserslist": {
Expand Down
15 changes: 6 additions & 9 deletions src/config/config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
const spectrum = process.env.REACT_APP_SPECTRUM_BASE_URL
? process.env.REACT_APP_SPECTRUM_BASE_URL
: window.location.origin;

const loginUrl = process.env.REACT_APP_LOGIN_BASE_URL
? process.env.REACT_APP_LOGIN_BASE_URL + '/login'
: window.location.origin + '/login';
const loginBaseURL = (directory) => {
return (process.env.REACT_APP_LOGIN_BASE_URL || window.location.origin) + directory + '?dest=' + encodeURIComponent(document.location.pathname + document.location.search);
};

const config = {
spectrum,
loginUrl,
spectrum: process.env.REACT_APP_SPECTRUM_BASE_URL || window.location.origin,
loginUrl: loginBaseURL('/auth/openid_connect'),
logoutUrl: loginBaseURL('/logout'),
datastores: {
list: [
{
Expand Down
43 changes: 17 additions & 26 deletions src/modules/profile/components/Login/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import React from 'react';
import config from '../../../../config';
import PropTypes from 'prop-types';

class Login extends Component {
render () {
const authenticated = this.props.profile && this.props.profile.status === 'Logged in';
const href = config.loginUrl + '?dest=' + encodeURIComponent(document.location.pathname + document.location.search);
const loading = this.props.loading;

return (
<>
{this.props.render({ href, authenticated, loading })}
</>
);
}
export default function Login ({ text = 'Login', link }) {
return (
<form
action={config.loginUrl}
method='post'
>
<button
type='submit'
className={link ? 'button-link-light' : 'button'}
>
{text}
</button>
</form>
);
}

Login.propTypes = {
profile: PropTypes.object,
loading: PropTypes.bool,
render: PropTypes.func
text: PropTypes.string,
link: PropTypes.string
};

function mapStateToProps (state) {
return {
profile: state.profile,
loading: !state.profile.status
};
}

export default connect(mapStateToProps)(Login);

0 comments on commit 9b0d4f8

Please sign in to comment.