fix (dashboard): redirect 404 local, revert changes (#3162)
### **User description** Revert to old `useNotFoundRedirect.ts` changes [d43931e](d43931e761) ___ ### **PR Type** Bug fix ___ ### **Description** - Simplified 404 redirect logic in useNotFoundRedirect hook - Removed platform-specific checks and unused imports - Updated conditions for redirecting to 404 page - Added changeset for minor version bump ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>useNotFoundRedirect.ts</strong><dd><code>Simplify useNotFoundRedirect hook logic</code> </dd></summary> <hr> dashboard/src/features/projects/common/hooks/useNotFoundRedirect/useNotFoundRedirect.ts <li>Removed unused imports and variables<br> <li> Simplified redirect conditions<br> <li> Removed platform-specific checks<br> <li> Updated dependencies in useEffect hook </details> </td> <td><a href="https://github.com/nhost/nhost/pull/3162/files#diff-837279cf43199053bca09913f62c4af019063a2e8dc7bfb7643ec54b7cecd29d">+10/-39</a> </td> </tr> </table></td></tr><tr><td><strong>Documentation</strong></td><td><table> <tr> <td> <details> <summary><strong>quick-seahorses-draw.md</strong><dd><code>Add changeset for 404 redirect fix</code> </dd></summary> <hr> .changeset/quick-seahorses-draw.md <li>Added changeset file for minor version bump<br> <li> Described fix for 404 redirect in Nhost CLI dashboard </details> </td> <td><a href="https://github.com/nhost/nhost/pull/3162/files#diff-df782a89bb7c2193ff124ea1262479d2d492088f1bf865064ead79328913642c">+5/-0</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > <details> <summary> Need help?</summary><li>Type <code>/help how to ...</code> in the comments thread for any questions about PR-Agent usage.</li><li>Check out the <a href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a> for more information.</li></details>
This commit is contained in:
5
.changeset/quick-seahorses-draw.md
Normal file
5
.changeset/quick-seahorses-draw.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@nhost/dashboard': minor
|
||||
---
|
||||
|
||||
fix: redirect to 404 with nhost cli dashboard
|
||||
@@ -1,35 +1,17 @@
|
||||
import { useIsPlatform } from '@/features/orgs/projects/common/hooks/useIsPlatform';
|
||||
import { useCurrentOrg } from '@/features/orgs/projects/hooks/useCurrentOrg';
|
||||
import { useProject } from '@/features/orgs/projects/hooks/useProject';
|
||||
import { useCurrentWorkspaceAndProject } from '@/features/projects/common/hooks/useCurrentWorkspaceAndProject';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
/**
|
||||
* Redirects to 404 page if either currentWorkspace/currentProject resolves to undefined
|
||||
* or if the current pathname is not a valid organization/project.
|
||||
* Not applicable if running dashboard with local Nhost backend.
|
||||
* Redirects to 404 page if either currentWorkspace/currentProject resolves to undefined.
|
||||
*/
|
||||
export default function useNotFoundRedirect() {
|
||||
const router = useRouter();
|
||||
const {
|
||||
query: {
|
||||
orgSlug: urlOrgSlug,
|
||||
workspaceSlug: urlWorkspaceSlug,
|
||||
appSubdomain: urlAppSubdomain,
|
||||
updating,
|
||||
appSlug: urlAppSlug,
|
||||
},
|
||||
query: { orgSlug, workspaceSlug, appSubdomain, updating, appSlug },
|
||||
isReady,
|
||||
} = router;
|
||||
|
||||
const { project, loading: projectLoading } = useProject();
|
||||
const isPlatform = useIsPlatform();
|
||||
const { org, loading: orgLoading } = useCurrentOrg();
|
||||
|
||||
const { subdomain: projectSubdomain } = project || {};
|
||||
const { slug: currentOrgSlug } = org || {};
|
||||
|
||||
const { currentProject, currentWorkspace, loading } =
|
||||
useCurrentWorkspaceAndProject();
|
||||
|
||||
@@ -41,10 +23,6 @@ export default function useNotFoundRedirect() {
|
||||
!isReady ||
|
||||
// If the current workspace and project are not loaded, we don't want to redirect to 404
|
||||
loading ||
|
||||
// If the project is loading, we don't want to redirect to 404
|
||||
projectLoading ||
|
||||
// If the org is loading, we don't want to redirect to 404
|
||||
orgLoading ||
|
||||
// If we're already on the 404 page, we don't want to redirect to 404
|
||||
router.pathname === '/404' ||
|
||||
router.pathname === '/' ||
|
||||
@@ -53,14 +31,12 @@ export default function useNotFoundRedirect() {
|
||||
router.pathname === '/run-one-click-install' ||
|
||||
router.pathname.includes('/orgs/_') ||
|
||||
router.pathname.includes('/orgs/_/projects/_') ||
|
||||
(!isPlatform &&
|
||||
router.pathname.includes('/orgs/[orgSlug]/projects/[appSubdomain]')) ||
|
||||
(urlOrgSlug === currentOrgSlug && !urlAppSubdomain) ||
|
||||
(urlOrgSlug === currentOrgSlug && urlAppSubdomain === projectSubdomain) ||
|
||||
orgSlug ||
|
||||
(orgSlug && appSubdomain) ||
|
||||
// If we are on a valid workspace and project, we don't want to redirect to 404
|
||||
(urlWorkspaceSlug && currentWorkspace && urlAppSlug && currentProject) ||
|
||||
(workspaceSlug && currentWorkspace && appSlug && currentProject) ||
|
||||
// If we are on a valid workspace and no project is selected, we don't want to redirect to 404
|
||||
(urlWorkspaceSlug && currentWorkspace && !urlAppSlug && !currentProject)
|
||||
(workspaceSlug && currentWorkspace && !appSlug && !currentProject)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -71,16 +47,11 @@ export default function useNotFoundRedirect() {
|
||||
currentWorkspace,
|
||||
isReady,
|
||||
loading,
|
||||
urlAppSubdomain,
|
||||
urlAppSlug,
|
||||
appSubdomain,
|
||||
appSlug,
|
||||
router,
|
||||
updating,
|
||||
projectLoading,
|
||||
orgLoading,
|
||||
currentOrgSlug,
|
||||
projectSubdomain,
|
||||
urlWorkspaceSlug,
|
||||
urlOrgSlug,
|
||||
isPlatform,
|
||||
workspaceSlug,
|
||||
orgSlug,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user