📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
got rid of redux-auth-wrapper dependency
Blue Mousef02c57a43ef2
diff --git a/package.json b/package.jsonindex 0f8f474c2..3fe9ff6f2 100644--- a/package.json+++ b/package.json@@ -35,7 +35,6 @@"react-router-hash-link": "^2.4.3","react-scripts": "5.0.0","redux": "^4.1.2",- "redux-auth-wrapper": "^3.0.0","redux-saga": "^1.1.3","swetrix": "^1.3.1","url": "^0.11.0"diff --git a/src/hoc/protected.js b/src/hoc/protected.jsindex 63541c820..10d5b43b8 100644--- a/src/hoc/protected.js+++ b/src/hoc/protected.js@@ -1,16 +1,29 @@-import { connectedRouterRedirect } from 'redux-auth-wrapper/history4/redirect'+import { useSelector } from 'react-redux'+import { useHistory } from 'react-router-dom'import routes from 'routes'-export const isAuthenticated = connectedRouterRedirect({- redirectPath: routes.signin,- authenticatedSelector: state => state.auth.authenticated,- wrapperDisplayName: 'userIsAuthenticated',- allowRedirectBack: false-})+export const auth = {+ authenticated: {+ selector: state => state.auth.authenticated,+ redirectPath: routes.signin,+ },+ notAuthenticated: {+ selector: state => !state.auth.authenticated,+ redirectPath: routes.dashboard,+ },+}-export const notAuthenticated = connectedRouterRedirect({- redirectPath: () => routes.dashboard,- authenticatedSelector: state => !state.auth.authenticated,- wrapperDisplayName: 'userIsNotAuthenticated',- allowRedirectBack: false-})+export const withAuthentication = (WrappedComponent, authParam) => {+ const WithAuthentication = (params) => {+ const selector = useSelector(authParam.selector)+ const history = useHistory()++ if (!selector) {+ history.push(authParam.redirectPath)+ }++ return <WrappedComponent {...params} />+ }++ return WithAuthentication+}diff --git a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx b/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsxindex 8a8f8d44d..487786537 100644--- a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx+++ b/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx@@ -3,7 +3,7 @@ import { Link, useHistory, useParams } from 'react-router-dom'import { useTranslation } from 'react-i18next'import { createNewPassword } from 'api'-import { notAuthenticated } from '../../../hoc/protected'+import { withAuthentication, auth } from 'hoc/protected'import Title from 'components/Title'import routes from 'routes'import Input from 'ui/Input'@@ -127,4 +127,4 @@ const CreateNewPassword = ({)}-export default notAuthenticated(memo(CreateNewPassword))+export default memo(withAuthentication(CreateNewPassword, auth.notAuthenticated))diff --git a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx b/src/pages/Auth/ForgotPassword/ForgotPassword.jsxindex cf850948d..eb8d69990 100644--- a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx+++ b/src/pages/Auth/ForgotPassword/ForgotPassword.jsx@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'import { forgotPassword } from 'api'import Title from 'components/Title'-import { notAuthenticated } from '../../../hoc/protected'+import { withAuthentication, auth } from 'hoc/protected'import routes from 'routes'import Input from 'ui/Input'import Button from 'ui/Button'@@ -109,4 +109,4 @@ const ForgotPassword = ({)}-export default notAuthenticated(memo(ForgotPassword))+export default memo(withAuthentication(ForgotPassword, auth.notAuthenticated))diff --git a/src/pages/Auth/Signin/Signin.jsx b/src/pages/Auth/Signin/Signin.jsxindex ad1bd7131..b3fd65320 100644--- a/src/pages/Auth/Signin/Signin.jsx+++ b/src/pages/Auth/Signin/Signin.jsx@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'import { useTranslation } from 'react-i18next'import Title from 'components/Title'-import { notAuthenticated } from '../../../hoc/protected'+import { withAuthentication, auth } from 'hoc/protected'import routes from 'routes'import Input from 'ui/Input'import Button from 'ui/Button'@@ -142,4 +142,4 @@ Signin.propTypes = {login: PropTypes.func.isRequired,}-export default notAuthenticated(memo(Signin))+export default memo(withAuthentication(Signin, auth.notAuthenticated))diff --git a/src/pages/Auth/Signup/Signup.jsx b/src/pages/Auth/Signup/Signup.jsxindex b71b75a61..729043beb 100644--- a/src/pages/Auth/Signup/Signup.jsx+++ b/src/pages/Auth/Signup/Signup.jsx@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'import { useTranslation, Trans } from 'react-i18next'import Title from 'components/Title'-import { notAuthenticated } from '../../../hoc/protected'+import { withAuthentication, auth } from 'hoc/protected'import routes from 'routes'import Input from 'ui/Input'import Checkbox from 'ui/Checkbox'@@ -172,4 +172,4 @@ Signup.propTypes = {signup: PropTypes.func.isRequired,}-export default notAuthenticated(memo(Signup))+export default memo(withAuthentication(Signup, auth.notAuthenticated))diff --git a/src/pages/Billing/index.jsx b/src/pages/Billing/index.jsxindex 3f1a1959b..ec4f12208 100644--- a/src/pages/Billing/index.jsx+++ b/src/pages/Billing/index.jsx@@ -3,7 +3,7 @@ import React from 'react'import { useTranslation, Trans } from 'react-i18next'import Pricing from '../MainPage/Pricing'-import { isAuthenticated } from '../../hoc/protected'+import { withAuthentication, auth } from 'hoc/protected'import Title from 'components/Title'// todo: create CONTACT_EMAIL variable and use it in the app@@ -37,4 +37,4 @@ const Features = () => {)}-export default isAuthenticated(Features)+export default withAuthentication(Features, auth.authenticated)diff --git a/src/pages/Dashboard/Dashboard.jsx b/src/pages/Dashboard/Dashboard.jsxindex 7c3bb0ce6..332cda6ad 100644--- a/src/pages/Dashboard/Dashboard.jsx+++ b/src/pages/Dashboard/Dashboard.jsx@@ -15,7 +15,7 @@ import { ArrowSmDownIcon } from '@heroicons/react/solid'import { XCircleIcon } from '@heroicons/react/solid'import Modal from 'ui/Modal'-import { isAuthenticated } from 'hoc/protected'+import { withAuthentication, auth } from 'hoc/protected'import Title from 'components/Title'import Loader from 'ui/Loader'import { ActivePin, InactivePin } from 'ui/Pin'@@ -220,4 +220,4 @@ Dashboard.defaultProps = {error: '',}-export default isAuthenticated(memo(Dashboard))+export default memo(withAuthentication(Dashboard, auth.authenticated))diff --git a/src/pages/MainPage/index.jsx b/src/pages/MainPage/index.jsxindex ecb1e8bee..d60bf5b94 100644--- a/src/pages/MainPage/index.jsx+++ b/src/pages/MainPage/index.jsx@@ -7,7 +7,7 @@ import _map from 'lodash/map'import routes from 'routes'// import { nFormatter } from 'utils/generic'-import { notAuthenticated } from '../../hoc/protected'+import { withAuthentication, auth } from '../../hoc/protected'import Title from 'components/Title'import SignUp from '../Auth/Signup/BasicSignup'import Pricing from './Pricing'@@ -272,4 +272,4 @@ const Main = () => {)}-export default memo(notAuthenticated(Main))+export default memo(withAuthentication(Main, auth.notAuthenticated))diff --git a/src/pages/Project/Settings/ProjectSettings.jsx b/src/pages/Project/Settings/ProjectSettings.jsxindex cf97d04bf..af4d6f27e 100644--- a/src/pages/Project/Settings/ProjectSettings.jsx+++ b/src/pages/Project/Settings/ProjectSettings.jsx@@ -11,7 +11,7 @@ import _split from 'lodash/split'import PropTypes from 'prop-types'import Title from 'components/Title'-import { isAuthenticated } from '../../../hoc/protected'+import { withAuthentication, auth } from 'hoc/protected'import { isSelfhosted } from 'redux/constants'import { createProject, updateProject, deleteProject } from 'api'import Input from 'ui/Input'@@ -277,4 +277,4 @@ ProjectSettings.propTypes = {user: PropTypes.object.isRequired,}-export default isAuthenticated(memo(ProjectSettings))+export default memo(withAuthentication(ProjectSettings, auth.authenticated))diff --git a/src/pages/UserSettings/UserSettings.container.jsx b/src/pages/UserSettings/UserSettings.container.jsxindex 8d79fb4b9..4aa65afdc 100644--- a/src/pages/UserSettings/UserSettings.container.jsx+++ b/src/pages/UserSettings/UserSettings.container.jsx@@ -9,7 +9,7 @@ import _isNull from 'lodash/isNull'import {CONFIRMATION_TIMEOUT, GDPR_REQUEST, GDPR_EXPORT_TIMEFRAME,} from 'redux/constants'-import { isAuthenticated } from 'hoc/protected'+import { withAuthentication, auth } from 'hoc/protected'import { authActions } from 'redux/actions/auth'import { errorsActions } from 'redux/actions/errors'import { alertsActions } from 'redux/actions/alerts'@@ -100,4 +100,4 @@ const UserSettingsContainer = () => {)}-export default isAuthenticated(memo(UserSettingsContainer))+export default memo(withAuthentication(UserSettingsContainer, auth.authenticated))