refactor(tags): improve server-side permission handling for tag access

- Added error handling for user permission fetching in the server-side props.
- Implemented a check for tag read permissions, redirecting unauthorized users to the home page.
- Enhanced the overall structure of the server-side logic for better clarity and maintainability.
This commit is contained in:
Mauricio Siu
2026-03-19 01:35:19 -06:00
parent 1d7509dfc2
commit 7f60000641
+10 -2
View File
@@ -38,11 +38,13 @@ export async function getServerSideProps(
transformer: superjson, transformer: superjson,
}); });
try {
await helpers.user.get.prefetch();
await helpers.settings.isCloud.prefetch(); await helpers.settings.isCloud.prefetch();
await helpers.user.get.prefetch(); const userPermissions = await helpers.user.getPermissions.fetch();
if (!user || user.role === "member") { if (!userPermissions?.tag.read) {
return { return {
redirect: { redirect: {
permanent: true, permanent: true,
@@ -50,9 +52,15 @@ export async function getServerSideProps(
}, },
}; };
} }
return { return {
props: { props: {
trpcState: helpers.dehydrate(), trpcState: helpers.dehydrate(),
}, },
}; };
} catch {
return {
props: {},
};
}
} }