-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added middleware check for organization and solution pages (#339)
- Loading branch information
Showing
1 changed file
with
18 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
/** | ||
* Check if the solution exists. If not, redirect to the parent organization page. | ||
* Check if the organization exists. If notm redirect to the home page. | ||
* Check if the organization exists. If not redirect to the home page. | ||
*/ | ||
export default defineNuxtRouteMiddleware(async (to, from) => { | ||
// FIXME: some type of bug in the login flow tries to navigate to /sw.js | ||
if (to.path === '/sw.js') | ||
return navigateTo('/') | ||
if (to.params.organizationslug) { | ||
const { data: organizations } = await useFetch('/api/organizations', { | ||
query: { slug: to.params.organizationslug } | ||
}) | ||
|
||
// const [{ data: solutions }, { data: organizations }] = await Promise.all([ | ||
// to.params.solutionSlug ? useFetch(`/api/solutions?slug=${to.params.solutionSlug}`, { cache: 'default' }) : { data: null }, | ||
// to.params.organizationslug ? useFetch(`/api/organizations?slug=${to.params.organizationslug}`, { cache: 'default' }) : { data: null } | ||
// ]) | ||
if (!(organizations?.value ?? []).length) { | ||
return navigateTo('/') | ||
} else if (to.params.solutionslug) { | ||
const { data: solutions } = await useFetch('/api/solutions', { | ||
query: { | ||
organizationSlug: to.params.organizationslug, | ||
slug: to.params.solutionslug | ||
} | ||
}) | ||
|
||
// if (!(solutions?.value ?? []).length) | ||
// return navigateTo(`/${to.params.organizationslug}`) | ||
|
||
// if (!(organizations?.value ?? []).length) | ||
// return navigateTo('/') | ||
if (!(solutions?.value ?? []).length) | ||
return navigateTo(`/o/${to.params.organizationslug}`) | ||
} | ||
} | ||
}) |