Skip to content

feat(server): with api server, service-lize#807

Merged
luoling8192 merged 44 commits into0.9.0from
dev/better-auth
Dec 25, 2025
Merged

feat(server): with api server, service-lize#807
luoling8192 merged 44 commits into0.9.0from
dev/better-auth

Conversation

@luoling8192
Copy link
Member

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @luoling8192, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the application by introducing a complete and robust authentication system. It involves setting up a new Hono-based API server with Drizzle ORM and better-auth for backend authentication logic, alongside comprehensive frontend integration in the Vue.js application. The changes cover everything from environment configuration and Dockerization to database schemas and user interface components for login and session management, aiming to provide a secure and scalable authentication solution.

Highlights

  • New API Server Introduction: A dedicated API server has been added under apps/server, built using Hono, Drizzle ORM, and the better-auth library to manage authentication.
  • Comprehensive Authentication System: Implemented a robust authentication flow supporting email/password, Google, and GitHub social logins, fully managed by the better-auth library.
  • Dockerization and Deployment Configuration: Included Dockerfile, Docker Compose, and Railway configuration files to streamline the setup, deployment, and management of the new API server and its PostgreSQL database.
  • Frontend Authentication Integration: The apps/stage-web frontend now seamlessly integrates with the new authentication system, featuring a dedicated login page, a user avatar dropdown for authenticated users, and enhanced session management.
  • Database Schema Definition: Drizzle ORM schemas for users, sessions, accounts, verification, and JWKS have been defined, providing a structured and type-safe approach to storing authentication-related data.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new authentication system using better-auth for both the server and client applications, including social logins with Google and GitHub. It sets up the necessary server-side infrastructure with Docker, a database schema, and API endpoints. The client-side is updated with a new login page and UI elements to reflect the authentication state. While the overall structure is sound, there are several critical and high-severity issues related to security, correctness, and configuration that need to be addressed. These include hardcoded secrets and URLs, lack of environment variable validation, and incorrect implementation of some authentication flows on the client side.

Comment on lines +30 to +33
- AUTH_GOOGLE_CLIENT_ID=changeme
- AUTH_GOOGLE_CLIENT_SECRET=changeme
- AUTH_GITHUB_CLIENT_ID=changeme
- AUTH_GITHUB_CLIENT_SECRET=changeme
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Hardcoding secrets, even placeholder ones like changeme, is a security risk. These values could accidentally be deployed to production. It's better to use environment variable substitution and load them from a .env file that is not committed to version control.

      - AUTH_GOOGLE_CLIENT_ID=${AUTH_GOOGLE_CLIENT_ID}
      - AUTH_GOOGLE_CLIENT_SECRET=${AUTH_GOOGLE_CLIENT_SECRET}
      - AUTH_GITHUB_CLIENT_ID=${AUTH_GITHUB_CLIENT_ID}
      - AUTH_GITHUB_CLIENT_SECRET=${AUTH_GITHUB_CLIENT_SECRET}

Comment on lines +36 to +37
baseURL: 'http://localhost:3000',
trustedOrigins: ['http://localhost:5173'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The baseURL and trustedOrigins are hardcoded. This will not work in staging or production environments and will cause authentication to fail. They should be configured via environment variables. You will need to add corresponding variables (e.g., BASE_URL, TRUSTED_ORIGINS) to your environment parsing in src/services/env.ts.

Suggested change
baseURL: 'http://localhost:3000',
trustedOrigins: ['http://localhost:5173'],
baseURL: env.BASE_URL,
trustedOrigins: (env.TRUSTED_ORIGINS || '').split(','),

Comment on lines +9 to +17
export function parseEnv(env: any): Env {
return {
DATABASE_URL: env.DATABASE_URL,
AUTH_GOOGLE_CLIENT_ID: env.AUTH_GOOGLE_CLIENT_ID,
AUTH_GOOGLE_CLIENT_SECRET: env.AUTH_GOOGLE_CLIENT_SECRET,
AUTH_GITHUB_CLIENT_ID: env.AUTH_GITHUB_CLIENT_ID,
AUTH_GITHUB_CLIENT_SECRET: env.AUTH_GITHUB_CLIENT_SECRET,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The parseEnv function doesn't validate the environment variables. If a required variable is missing, it will be undefined, leading to runtime errors that are hard to debug. You should add validation to ensure all required variables are present on startup. Using a library like zod is highly recommended for this. You would need to add zod as a dependency.

Suggested change
export function parseEnv(env: any): Env {
return {
DATABASE_URL: env.DATABASE_URL,
AUTH_GOOGLE_CLIENT_ID: env.AUTH_GOOGLE_CLIENT_ID,
AUTH_GOOGLE_CLIENT_SECRET: env.AUTH_GOOGLE_CLIENT_SECRET,
AUTH_GITHUB_CLIENT_ID: env.AUTH_GITHUB_CLIENT_ID,
AUTH_GITHUB_CLIENT_SECRET: env.AUTH_GITHUB_CLIENT_SECRET,
}
}
import { z } from 'zod'
const envSchema = z.object({
DATABASE_URL: z.string().url(),
AUTH_GOOGLE_CLIENT_ID: z.string().min(1),
AUTH_GOOGLE_CLIENT_SECRET: z.string().min(1),
AUTH_GITHUB_CLIENT_ID: z.string().min(1),
AUTH_GITHUB_CLIENT_SECRET: z.string().min(1),
// Add other required env vars like BASE_URL, CORS_ORIGINS, etc.
})
export function parseEnv(env: any): Env {
return envSchema.parse(env)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow this.

app.use(
'/api/auth/*', // or replace with "*" to enable cors for all routes
cors({
origin: ['http://localhost:5173', 'https://airi.moeru.ai'], // replace with your origin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The CORS origins are hardcoded. This makes it difficult to manage different environments (development, staging, production). These should be configured via an environment variable. You would also need to add the corresponding variable (e.g., CORS_ORIGINS) to your environment parsing in src/services/env.ts.

      origin: (env.CORS_ORIGINS || '').split(','), // Example: load from a comma-separated string in env

Comment on lines +24 to +26
updatedAt: timestamp('updated_at')
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The updatedAt column in the session table is missing .defaultNow(). This is inconsistent with the user and verification tables, and means the updatedAt field will be NOT NULL but have no default value on creation. The same issue exists for the account table on lines 53-55.

Suggested change
updatedAt: timestamp('updated_at')
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),
updatedAt: timestamp('updated_at')
.defaultNow()
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),

Comment on lines +17 to +31
}, {
onSuccess: (ctx: any) => {
const authToken = ctx.response.headers.get('set-auth-token') // get the token from the response headers
if (authToken) {
useAuthStore().authToken = authToken
}
},
onError: (ctx: any) => {
isLoading.value = false
toast.error(ctx.error.message || 'Failed to sign in')
},
}).catch((error: any) => {
isLoading.value = false
toast.error(error instanceof Error ? error.message : 'An unknown error occurred')
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The onSuccess, onError callbacks and the catch block use any for their parameters. This sacrifices type safety. You should provide proper types for ctx and error to leverage TypeScript's benefits and prevent potential runtime errors. You can likely import the context types from better-auth or define them based on the library's API.

Comment on lines +97 to +103
<div class="mt-10 flex items-center justify-center gap-6 text-xs text-gray-500 font-medium">
<a href="#" class="transition-colors hover:text-white">Terms</a>
<span class="h-1 w-1 rounded-full bg-gray-700" />
<a href="#" class="transition-colors hover:text-white">Privacy</a>
<span class="h-1 w-1 rounded-full bg-gray-700" />
<a href="#" class="transition-colors hover:text-white">Help</a>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The links for "Terms", "Privacy", and "Help" are placeholders pointing to "#". These should either be implemented with links to the correct pages or removed if not applicable.

@railway-app railway-app bot temporarily deployed to cooperative-rejoicing / production December 16, 2025 17:50 Inactive
@railway-app railway-app bot temporarily deployed to cooperative-rejoicing / production December 16, 2025 18:26 Inactive
@nekomeowww nekomeowww changed the title Dev/better auth [DO NOT MERGE] feat(server): with api server, service-lize Dec 17, 2025
@railway-app railway-app bot temporarily deployed to API / Production December 17, 2025 03:13 Inactive
@luoling8192 luoling8192 marked this pull request as ready for review December 18, 2025 13:44
@railway-app railway-app bot temporarily deployed to API / production December 18, 2025 13:47 Inactive
@railway-app railway-app bot temporarily deployed to API / production December 18, 2025 13:50 Inactive
@railway-app railway-app bot temporarily deployed to API / production December 24, 2025 16:53 Inactive
@railway-app railway-app bot temporarily deployed to API / production December 24, 2025 16:56 Inactive
Co-authored-by: Neko <neko@ayaka.moe>
@railway-app railway-app bot temporarily deployed to API / production December 25, 2025 11:49 Inactive
Co-authored-by: Neko Ayaka <neko@ayaka.moe>
@railway-app railway-app bot temporarily deployed to API / production December 25, 2025 11:57 Inactive
@railway-app railway-app bot temporarily deployed to API / production December 25, 2025 12:03 Inactive
@railway-app railway-app bot temporarily deployed to API / production December 25, 2025 12:20 Inactive
@railway-app railway-app bot temporarily deployed to API / production December 25, 2025 12:22 Inactive
@luoling8192 luoling8192 merged commit 55d8686 into 0.9.0 Dec 25, 2025
1 check failed
@luoling8192 luoling8192 deleted the dev/better-auth branch December 25, 2025 12:33
nekomeowww added a commit that referenced this pull request Dec 28, 2025
Co-authored-by: Neko Ayaka <neko@ayaka.moe>
Co-authored-by: Lovehsigure_520 <1260907335@qq.com>
nekomeowww added a commit that referenced this pull request Dec 29, 2025
Co-authored-by: Neko Ayaka <neko@ayaka.moe>
Co-authored-by: Lovehsigure_520 <1260907335@qq.com>
nekomeowww added a commit that referenced this pull request Dec 30, 2025
Co-authored-by: Neko Ayaka <neko@ayaka.moe>
Co-authored-by: Lovehsigure_520 <1260907335@qq.com>
luoling8192 added a commit that referenced this pull request Jan 5, 2026
Co-authored-by: Neko Ayaka <neko@ayaka.moe>
Co-authored-by: Lovehsigure_520 <1260907335@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants