epicweb-dev / epic-stack

This is a Full Stack app starter with the foundational things setup and configured for you to hit the ground running on your next EPIC idea.
https://www.epicweb.dev/epic-stack
MIT License
4.9k stars 398 forks source link

Server-only module referenced by client #609

Closed gregleeper closed 10 months ago

gregleeper commented 10 months ago

I have borrowed the role based permissions model from the epic-stack. I am using it with the Vite Remix plugin. It notified me that the #/utils/permissions.ts file, which is client side, is referencing the #/utils/auth.server.ts file, which is server only code.

[remix] 4:15:19 PM [vite] Internal server error: Server-only module referenced by client
[remix] 
[remix]     './auth.server.js' imported by 'app/utils/permissions.ts'
kentcdodds commented 10 months ago

Ah yeah, that'll need to be refactored a bit to separate the server-only utils from the UI utils.

itsmegood commented 10 months ago

Kent i looked through and found that permission.ts is only called a single place in the client https://github.com/epicweb-dev/epic-stack/blob/main/app/routes/users%2B/%24username_%2B/notes.%24noteId.tsx#L112

If you like we can remove either that and pass something is isOwner (boolean) down from loader and remove the code entirely and then convert permission.ts to fully server side.

kentcdodds commented 10 months ago

The utility is useful for people to use as they build out their site, so we should split them up into a .server file for the server stuff and a regular file for the UI stuff

gregleeper commented 10 months ago

For me, I moved userHasPermission and userHasRole to the user.ts utility as it made just as much sense there. I moved the rest of the permissions.ts file to the permissions.server.ts file.

kentcdodds commented 10 months ago

This has been resolved. Thanks everyone!