Added redirect on unauthorized route BOD-162
This commit is contained in:
@@ -1,23 +1,24 @@
|
|||||||
import { LockOutlined, UserOutlined } from "@ant-design/icons";
|
import { LockOutlined, UserOutlined } from "@ant-design/icons";
|
||||||
import { Button, Form, Input, Typography } from "antd";
|
import { Button, Form, Input, Typography } from "antd";
|
||||||
|
import queryString from "query-string";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useApolloClient } from "react-apollo";
|
import { useApolloClient } from "react-apollo";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { Redirect, Link } from "react-router-dom";
|
import { Link, Redirect, useLocation } from "react-router-dom";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import ImEXOnlineLogo from "../../assets/logo240.png";
|
import ImEXOnlineLogo from "../../assets/logo240.png";
|
||||||
import { UPSERT_USER } from "../../graphql/user.queries";
|
import { UPSERT_USER } from "../../graphql/user.queries";
|
||||||
import {
|
import {
|
||||||
emailSignInStart,
|
emailSignInStart,
|
||||||
sendPasswordReset,
|
sendPasswordReset
|
||||||
} from "../../redux/user/user.actions";
|
} from "../../redux/user/user.actions";
|
||||||
import {
|
import {
|
||||||
selectCurrentUser,
|
selectCurrentUser,
|
||||||
selectSignInError,
|
selectSignInError
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import "./sign-in-form.styles.scss";
|
|
||||||
import AlertComponent from "../alert/alert.component";
|
import AlertComponent from "../alert/alert.component";
|
||||||
|
import "./sign-in-form.styles.scss";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentUser: selectCurrentUser,
|
currentUser: selectCurrentUser,
|
||||||
@@ -36,6 +37,7 @@ export function SignInComponent({
|
|||||||
signInError,
|
signInError,
|
||||||
sendPasswordReset,
|
sendPasswordReset,
|
||||||
}) {
|
}) {
|
||||||
|
const { redirect } = queryString.parse(useLocation().search);
|
||||||
const apolloClient = useApolloClient();
|
const apolloClient = useApolloClient();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const handleFinish = (values) => {
|
const handleFinish = (values) => {
|
||||||
@@ -60,7 +62,8 @@ export function SignInComponent({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentUser.authorized === true) return <Redirect to='/manage' />;
|
if (currentUser.authorized === true)
|
||||||
|
return <Redirect to={redirect || "/manage"} />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='login-container'>
|
<div className='login-container'>
|
||||||
|
|||||||
@@ -1,17 +1,12 @@
|
|||||||
|
import { Button, Form, Result } from "antd";
|
||||||
|
import React from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import {
|
import { sendPasswordReset } from "../../redux/user/user.actions";
|
||||||
sendPasswordReset,
|
|
||||||
validatePasswordResetStart,
|
|
||||||
} from "../../redux/user/user.actions";
|
|
||||||
import queryString from "query-string";
|
|
||||||
import { useLocation } from "react-router-dom";
|
|
||||||
import { Input, Form, Button, Result } from "antd";
|
|
||||||
import React, { useState } from "react";
|
|
||||||
import EmailFormItemComponent from "../form-items-formatted/email-form-item.component";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { selectPasswordReset } from "../../redux/user/user.selectors";
|
import { selectPasswordReset } from "../../redux/user/user.selectors";
|
||||||
import AlertComponent from "../alert/alert.component";
|
import AlertComponent from "../alert/alert.component";
|
||||||
|
import EmailFormItemComponent from "../form-items-formatted/email-form-item.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
passwordReset: selectPasswordReset,
|
passwordReset: selectPasswordReset,
|
||||||
|
|||||||
@@ -1,26 +1,10 @@
|
|||||||
import React from "react";
|
|
||||||
|
|
||||||
import { connect } from "react-redux";
|
|
||||||
import { createStructuredSelector } from "reselect";
|
|
||||||
import {
|
|
||||||
sendPasswordReset,
|
|
||||||
validatePasswordResetStart,
|
|
||||||
} from "../../redux/user/user.actions";
|
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
|
import React from "react";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
import UserValidatePwReset from "../../components/user-validate-pw-reset/user-validate-pw-reset.component";
|
|
||||||
import UserRequestResetPw from "../../components/user-request-pw-reset/user-request-reset-pw.component";
|
import UserRequestResetPw from "../../components/user-request-pw-reset/user-request-reset-pw.component";
|
||||||
|
import UserValidatePwReset from "../../components/user-validate-pw-reset/user-validate-pw-reset.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
export default function ResetPassword() {
|
||||||
//currentUser: selectCurrentUser
|
|
||||||
});
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
|
||||||
sendPasswordReset: (email) => dispatch(sendPasswordReset(email)),
|
|
||||||
validatePasswordReset: (emailAndPin) =>
|
|
||||||
dispatch(validatePasswordResetStart(emailAndPin)),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default function ResetPassword({}) {
|
|
||||||
const searchParams = queryString.parse(useLocation().search);
|
const searchParams = queryString.parse(useLocation().search);
|
||||||
const { mode, oobCode } = searchParams;
|
const { mode, oobCode } = searchParams;
|
||||||
console.log("ResetPassword -> mode, oobCode", mode, oobCode);
|
console.log("ResetPassword -> mode, oobCode", mode, oobCode);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Route, Redirect } from "react-router-dom";
|
import { Route, Redirect, useLocation } from "react-router-dom";
|
||||||
export default ({ component: Component, isAuthorized, ...rest }) => {
|
export default ({ component: Component, isAuthorized, ...rest }) => {
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Route
|
<Route
|
||||||
{...rest}
|
{...rest}
|
||||||
@@ -8,7 +10,7 @@ export default ({ component: Component, isAuthorized, ...rest }) => {
|
|||||||
isAuthorized === true ? (
|
isAuthorized === true ? (
|
||||||
<Component {...props} />
|
<Component {...props} />
|
||||||
) : (
|
) : (
|
||||||
<Redirect to="/signin" />
|
<Redirect to={`/signin?redirect=${location.pathname}`} />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user