-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: redirect on hidden category after login (#893)
- Loading branch information
1 parent
846864e
commit b1b65b1
Showing
9 changed files
with
72 additions
and
62 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* This middleware is used to check if category can be accesed without being authenticatedd. | ||
* | ||
* If the user is not authenticated, the user will be redirected to the login page. | ||
*/ | ||
import { categoryGetters } from '@plentymarkets/shop-api'; | ||
export default defineNuxtRouteMiddleware(async (to) => { | ||
const { getFacetsFromURL, checkFiltersInURL } = useCategoryFilter(to); | ||
const { setCategoriesPageMeta } = useCanonical(); | ||
const { isAuthorized, getSession } = useCustomer(); | ||
await getSession(); | ||
const { data: productsCatalog, fetchProducts, checkingPermission } = useProducts(); | ||
const localePath = useLocalePath(); | ||
checkingPermission.value = true; | ||
const params = getFacetsFromURL(); | ||
await fetchProducts(params).then(() => checkFiltersInURL()); | ||
if (!productsCatalog.value.category) { | ||
throw createError({ statusCode: 404, statusMessage: 'Not found', fatal: true }); | ||
} | ||
setCategoriesPageMeta(productsCatalog.value, params); | ||
|
||
const category = productsCatalog.value?.category; | ||
if (category && categoryGetters.hasCustomerRight(category) && !isAuthorized.value) { | ||
const targetUrl = to.fullPath; | ||
return navigateTo({ | ||
path: localePath(paths.authLogin), | ||
query: { redirect: targetUrl }, | ||
}); | ||
} | ||
checkingPermission.value = false; | ||
}); |
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
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
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