feat: add better-auth - #10
Conversation
There was a problem hiding this comment.
Pull request overview
This PR integrates better-auth as the authentication solution by removing Sentry configuration and the entire notify service. The changes introduce Discord OAuth client credentials and better-auth URL/secret environment variables while simplifying the validator schemas.
Key Changes:
- Replaced Sentry configuration with better-auth environment variables (URL, secret, Discord OAuth credentials)
- Removed the entire notify service and its scheduled notification functionality
- Simplified validator schemas by removing history-related schemas and adding a sample schema
- Updated backend configuration to include better-auth environment variables
Reviewed changes
Copilot reviewed 82 out of 88 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| setup/src/types.ts | Removed Sentry and notify config types, added better-auth configuration fields |
| setup/src/index.ts | Removed Sentry environment variables and notify wrangler config, added better-auth vars to backend |
| setup/src/functions.ts | Updated environment variable loading to replace Sentry vars with better-auth credentials |
| products/validator/src/response/sample.ts | Added new sample schema replacing history schemas |
| products/validator/src/response/*.ts | Removed history-related response schemas |
| products/validator/src/request/*.ts | Removed history-related request schemas |
| products/validator/src/index.ts | Updated exports to remove history schemas and export sample schema |
| products/validator/README.md | Updated documentation to remove notify service references |
| products/notify/* | Entire notify service removed including wrangler config, source code, and tests |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }) | ||
| .or(z.null()); | ||
|
|
||
| export type sampleSchemaType = z.infer<typeof sampleSchema>; |
There was a problem hiding this comment.
The type name sampleSchemaType doesn't follow TypeScript naming conventions. Type names should be in PascalCase. Consider renaming to SampleSchemaType for consistency with TypeScript best practices.
| import { HTTPException } from 'hono/http-exception'; | ||
| import { cors } from 'hono/cors'; | ||
| import type { ErrorResponseSchemaType } from 'validator'; | ||
| import { errorResponseSchema, type ErrorResponseSchemaType } from 'validator'; |
There was a problem hiding this comment.
Unused import errorResponseSchema.
| import { errorResponseSchema, type ErrorResponseSchemaType } from 'validator'; | |
| import type { ErrorResponseSchemaType } from 'validator'; |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 66340d1d14
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await authClient.signIn.social({ | ||
| provider: 'discord', | ||
| callbackURL: 'http://localhost:5173/', | ||
| }); |
There was a problem hiding this comment.
Avoid hardcoded localhost OAuth callback
The callbackURL is fixed to http://localhost:5173/. When the frontend is deployed on any other origin, the OAuth provider will redirect users back to localhost, which fails or lands on the wrong app, effectively breaking sign‑in in production. Use the current origin or a configurable env value so the callback matches the deployed site.
Useful? React with 👍 / 👎.
| baseURL: env.BETTER_AUTH_URL, | ||
| // allow requests from the frontend development server | ||
| trustedOrigins: ['http://localhost:5173'], | ||
| socialProviders: { |
There was a problem hiding this comment.
Trust production origin for better-auth requests
The auth server only trusts http://localhost:5173. better-auth enforces an Origin check via trustedOrigins, so requests from the production frontend origin (e.g., the one already used in CORS config) will be rejected, preventing login/session calls in production. Add the production origin (or derive it from env) alongside localhost.
Useful? React with 👍 / 👎.
No description provided.