* Restricts new signups on staging to explicit GitHub ID or email allowlists. * GitHub IDs are immutable, unlike usernames. No-op outside staging. * * This is a thin UX layer only — it rejects disallowed users during OAuth * before a `user` row is created, so /error shows "staging is invite-only
(env: Cloudflare.Env)
| 257 | * blocks spend on the production provider keys held by staging-gen. See #11137. |
| 258 | */ |
| 259 | function stagingAccessPlugin(env: Cloudflare.Env): BetterAuthPlugin { |
| 260 | if (env.ENVIRONMENT !== "staging") { |
| 261 | return { id: "staging-access" }; |
| 262 | } |
| 263 | return { |
| 264 | id: "staging-access", |
| 265 | init: () => ({ |
| 266 | options: { |
| 267 | databaseHooks: { |
| 268 | user: { |
| 269 | create: { |
| 270 | before: async (user: GenericUser) => { |
| 271 | try { |
| 272 | assertStagingAccess(env, { |
| 273 | githubId: ( |
| 274 | user as { githubId?: number } |
| 275 | ).githubId, |
| 276 | email: user.email, |
| 277 | }); |
| 278 | } catch (e) { |
| 279 | if (e instanceof StagingAccessDeniedError) { |
| 280 | throw new APIError("FORBIDDEN", { |
| 281 | message: e.message, |
| 282 | }); |
| 283 | } |
| 284 | throw e; |
| 285 | } |
| 286 | return { data: user }; |
| 287 | }, |
| 288 | }, |
| 289 | }, |
| 290 | }, |
| 291 | } satisfies Partial<BetterAuthOptions>, |
| 292 | }), |
| 293 | } satisfies BetterAuthPlugin; |
| 294 | } |
no test coverage detected