Skip to content

📈 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!

fixed signin redirects for password protected projects

Blue Mouseb7efdf2d1cff
diff --git a/app/modals/NewFunnel.tsx b/app/modals/NewFunnel.tsx
index 96ebb6391..d1b7869fc 100644
--- a/app/modals/NewFunnel.tsx
+++ b/app/modals/NewFunnel.tsx
@@ -1,6 +1,7 @@
import React, { useState, useEffect, useMemo } from 'react'
import _map from 'lodash/map'
import _every from 'lodash/every'
+import _isUndefined from 'lodash/isUndefined'
import cx from 'clsx'
import { TrashIcon } from '@heroicons/react/24/outline'
import { useTranslation } from 'react-i18next'
@@ -11,8 +12,10 @@ import Combobox from 'ui/Combobox'
import { MIN_FUNNEL_STEPS, MAX_FUNNEL_STEPS } from 'redux/constants'
import { getFilters } from 'api'
import { IFunnel } from 'redux/models/IProject'
+import { IProjectForShared } from 'redux/models/ISharedProject'
interface INewFunnel {
+ project: IProjectForShared,
onClose: () => void,
onSubmit: (name: string, steps: string[]) => Promise<void>,
isOpened: boolean,
@@ -24,7 +27,7 @@ interface INewFunnel {
const INITIAL_FUNNEL_STEPS = [null, null]
const NewFunnel = ({
- onClose, onSubmit, isOpened, pid, funnel, loading,
+ onClose, onSubmit, isOpened, pid, funnel, loading, project,
}: INewFunnel): JSX.Element => {
const { t } = useTranslation('common')
const [name, setName] = useState<string>(funnel?.name || '')
@@ -42,6 +45,12 @@ const NewFunnel = ({
}, [isOpened, funnel])
useEffect(() => {
+ // if project.name is underfined - that means that project is not loaded yet
+ // (it may be password protected, hence making a filters list request will fail with 403)
+ if (_isUndefined(project.name)) {
+ return
+ }
+
const getFiltersData = async () => {
let pgFilters: string[] = []
let ceFilters: string[] = []
@@ -65,7 +74,7 @@ const NewFunnel = ({
}
getFiltersData()
- }, [pid])
+ }, [pid, project])
const _onClose = () => {
setTimeout(() => {
diff --git a/app/pages/Project/View/ViewProject.tsx b/app/pages/Project/View/ViewProject.tsx
index ca8951993..b2986988f 100644
--- a/app/pages/Project/View/ViewProject.tsx
+++ b/app/pages/Project/View/ViewProject.tsx
@@ -1845,55 +1845,57 @@ const ViewProject = ({
// loadProject if project is empty so more often it is need for public projects
useEffect(() => {
- if (!isLoading && _isEmpty(project)) {
- getProject(id, false, projectPassword)
- .then(projectRes => {
- if (!_isEmpty(projectRes)) {
- if (projectRes.isPasswordProtected && !projectRes.isOwner && _isEmpty(projectPassword)) {
- navigate(_replace(routes.project_protected_password, ':id', id))
- return
- }
+ if (isLoading || !_isEmpty(project)) {
+ return
+ }
- if ((projectRes.isPublic || projectRes?.isPasswordProtected) && !projectRes.isOwner) {
- getOverallStats([id], projectPassword)
- .then(res => {
- setPublicProject({
- ...projectRes,
- overall: res[id],
- })
- })
- .catch(e => {
- console.error(e)
- onErrorLoading()
- })
- } else {
- getOverallStats([id])
- .then(res => {
- setProjects([...(projects as any[]), {
- ...projectRes,
- overall: res[id],
- }])
- })
- .then(() => {
- return getLiveVisitors([id], projectPassword)
- })
- .then(res => {
- setLiveStatsForProject(id, res[id])
- })
- .catch(e => {
- console.error(e)
- onErrorLoading()
- })
- }
- } else {
- onErrorLoading()
- }
- })
- .catch(e => {
- console.error(e)
+ getProject(id, false, projectPassword)
+ .then(projectRes => {
+ if (_isEmpty(projectRes)) {
onErrorLoading()
- })
- }
+ }
+
+ if (projectRes.isPasswordProtected && !projectRes.isOwner && _isEmpty(projectPassword)) {
+ navigate(_replace(routes.project_protected_password, ':id', id))
+ return
+ }
+
+ if ((projectRes.isPublic || projectRes?.isPasswordProtected) && !projectRes.isOwner) {
+ getOverallStats([id], projectPassword)
+ .then(res => {
+ setPublicProject({
+ ...projectRes,
+ overall: res[id],
+ })
+ })
+ .catch(e => {
+ console.error('[ERROR] (getProject -> getOverallStats public)', e)
+ onErrorLoading()
+ })
+ } else {
+ getOverallStats([id])
+ .then(res => {
+ setProjects([...(projects as any[]), {
+ ...projectRes,
+ overall: res[id],
+ }])
+ })
+ .then(() => {
+ return getLiveVisitors([id], projectPassword)
+ })
+ .then(res => {
+ setLiveStatsForProject(id, res[id])
+ })
+ .catch(e => {
+ console.error('[ERROR] (getProject -> getOverallStats)', e)
+ onErrorLoading()
+ })
+ }
+ })
+ .catch(e => {
+ console.error('[ERROR] (getProject)', e)
+ onErrorLoading()
+ })
}, [isLoading, project, id, setPublicProject]) // eslint-disable-line
// updatePeriod using for update period and timeBucket also update url
@@ -2978,6 +2980,7 @@ const ViewProject = ({
tb={timeBucket}
/>
<NewFunnel
+ project={project}
pid={id}
funnel={funnelToEdit}
isOpened={isNewFunnelOpened}
diff --git a/app/redux/sagas/ui/load_projects.ts b/app/redux/sagas/ui/load_projects.ts
index 6bdb9fe2e..1ea7c93f9 100644
--- a/app/redux/sagas/ui/load_projects.ts
+++ b/app/redux/sagas/ui/load_projects.ts
@@ -2,6 +2,7 @@ import { put, call } from 'redux-saga/effects'
import _map from 'lodash/map'
import _isString from 'lodash/isString'
import Debug from 'debug'
+import { getAccessToken } from 'utils/accessToken'
import UIActions from 'redux/reducers/ui'
@@ -14,6 +15,12 @@ const {
const debug = Debug('swetrix:rx:s:load-projects')
export default function* loadProjects({ payload: { take = ENTRIES_PER_PAGE_DASHBOARD, skip = 0, isCaptcha = false, search = '' } }) {
+ const token = getAccessToken()
+
+ if (!token) {
+ return
+ }
+
try {
if (isCaptcha) {
yield put(UIActions.setCaptchaLoading(true))