fix: Do not re-signin if user is already authed
This commit is contained in:
@ -2,6 +2,7 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
import { navigate as gatsbyNavigate } from 'gatsby';
|
||||||
import { Button } from '@freecodecamp/react-bootstrap';
|
import { Button } from '@freecodecamp/react-bootstrap';
|
||||||
|
|
||||||
import { hardGoTo, isSignedInSelector } from '../../../redux';
|
import { hardGoTo, isSignedInSelector } from '../../../redux';
|
||||||
@ -11,27 +12,26 @@ import { gtagReportConversion } from '../../../analytics/gtag';
|
|||||||
|
|
||||||
import './login.css';
|
import './login.css';
|
||||||
|
|
||||||
const mapStateToProps = createSelector(
|
const mapStateToProps = createSelector(isSignedInSelector, isSignedIn => ({
|
||||||
isSignedInSelector,
|
isSignedIn
|
||||||
({ isSingedIn }) => ({ isSingedIn })
|
}));
|
||||||
);
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
navigate: location => dispatch(hardGoTo(location))
|
navigate: location => dispatch(hardGoTo(location))
|
||||||
});
|
});
|
||||||
|
|
||||||
const createOnClick = (navigate, isSingedIn) => e => {
|
const createOnClick = (navigate, isSignedIn) => e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
gtagReportConversion();
|
gtagReportConversion();
|
||||||
if (isSingedIn) {
|
if (isSignedIn) {
|
||||||
return navigate('/welcome');
|
return gatsbyNavigate('/welcome');
|
||||||
}
|
}
|
||||||
return navigate(`${apiLocation}/signin`);
|
return navigate(`${apiLocation}/signin`);
|
||||||
};
|
};
|
||||||
|
|
||||||
function Login(props) {
|
function Login(props) {
|
||||||
const { children, navigate, isSingedIn, ...restProps } = props;
|
const { children, navigate, isSignedIn, ...restProps } = props;
|
||||||
return (
|
return (
|
||||||
<a href='/signin' onClick={createOnClick(navigate, isSingedIn)}>
|
<a href='/signin' onClick={createOnClick(navigate, isSignedIn)}>
|
||||||
<Button
|
<Button
|
||||||
{...restProps}
|
{...restProps}
|
||||||
bsStyle='default'
|
bsStyle='default'
|
||||||
@ -48,7 +48,7 @@ function Login(props) {
|
|||||||
Login.displayName = 'Login';
|
Login.displayName = 'Login';
|
||||||
Login.propTypes = {
|
Login.propTypes = {
|
||||||
children: PropTypes.any,
|
children: PropTypes.any,
|
||||||
isSingedIn: PropTypes.bool,
|
isSignedIn: PropTypes.bool,
|
||||||
navigate: PropTypes.func.isRequired
|
navigate: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user