I'm encountering an issue with getServerSideProps
in NextJS where the values are not updating on page load. It seems to behave similarly to using getStaticProps
when retrieving data from an imported JSON file.
Here is the relevant code snippet:
/update/[...id].js
import { hasPermission, getPermissions } from '../../lib/permissions'
...
// Using ternary operator to check user permission within the page function
{ (hasPermission(session.user.email, `${params.id[0]}-edit`, permissions)) ? <HasPerm /> : <NoPerm /> }
...
export async function getServerSideProps(context) {
const params = context.query
const permissions = getPermissions()
return {
props: { params, permissions }
}
}
/lib/permissions.js
import permissions from '../db/users.json'
export function hasPermission(username, group, perm = false) {
if (!perm)
perm = permissions
if (username in perm && perm[username].groups.includes(group)) {
return true
}
if (perm.all.groups.includes(group)) {
return true
}
return false
}
export function getPermissions() {
return permissions
}
For SSR pages that were originally following this pattern, I passed permissions into the page via getStaticProps
and utilized those values in my hasPermission()
function to ensure revalidation upon permission changes. However, as there isn't a revalidation option in getServerSideProps
, the data remains static. Previously, I used getInitialProps
but it's generally discouraged due to ASO limitations.
How can I utilize getServerSideProps
while ensuring revalidation of my imported JSON?