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

View File

@@ -38,21 +38,29 @@ export async function getServerSideProps(
transformer: superjson,
});
await helpers.settings.isCloud.prefetch();
try {
await helpers.user.get.prefetch();
await helpers.settings.isCloud.prefetch();
await helpers.user.get.prefetch();
const userPermissions = await helpers.user.getPermissions.fetch();
if (!userPermissions?.tag.read) {
return {
redirect: {
permanent: true,
destination: "/",
},
};
}
if (!user || user.role === "member") {
return {
redirect: {
permanent: true,
destination: "/",
props: {
trpcState: helpers.dehydrate(),
},
};
} catch {
return {
props: {},
};
}
return {
props: {
trpcState: helpers.dehydrate(),
},
};
}