You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For GET requests, prefer using API routes with react-query over server actions. This provides caching benefits and better control over data refetching.
Server actions should be used for mutations (POST/PUT/DELETE operations), not for data fetching.
129
+
130
+
## Authentication
131
+
132
+
Use `withAuthV2` or `withOptionalAuthV2` from `@/withAuthV2` to protect server actions and API routes.
133
+
134
+
-**`withAuthV2`** - Requires authentication. Returns `notAuthenticated()` if user is not logged in.
135
+
-**`withOptionalAuthV2`** - Allows anonymous access if the org has anonymous access enabled. `user` may be `undefined`.
136
+
-**`withMinimumOrgRole`** - Wrap inside auth context to require a minimum role (e.g., `OrgRole.OWNER`).
137
+
138
+
**Important:** Always use the `prisma` instance provided by the auth context. This instance has `userScopedPrismaClientExtension` applied, which enforces repository visibility rules (e.g., filtering repos based on user permissions). Do NOT import `prisma` directly from `@/prisma` in actions or routes that return data to the client.
139
+
140
+
**Server actions** - Wrap with `sew()` for error handling:
0 commit comments