Open source personal finance application
refactor: clean up auth config — remove redundant hook and CORS origins
Ilya Komichev6e93b7a0e3e9
diff --git a/convex/auth.ts b/convex/auth.tsindex d3391850..44d79a14 100644--- a/convex/auth.ts+++ b/convex/auth.ts@@ -3,7 +3,6 @@ import type { GenericCtx } from '@convex-dev/better-auth'import { createClient } from '@convex-dev/better-auth'import { convex, crossDomain } from '@convex-dev/better-auth/plugins'import { betterAuth } from 'better-auth'-import { createAuthMiddleware } from 'better-auth/plugins'import type { DataModel } from './_generated/dataModel'@@ -17,26 +16,11 @@ export const authComponent = createClient<DataModel>(components.betterAuth)function createAuth(ctx: GenericCtx<DataModel>) {return betterAuth({- baseURL: siteUrl,- database: authComponent.adapter(ctx),- hooks: {- before: createAuthMiddleware(async (ctx) => {- // The convex plugin only sets disableRefresh for /get-session.- // /convex/token also uses sessionMiddleware → getSession() internally,- // but without disableRefresh the session refresh can fail in cross-domain- // context (HTTP action can't reliably persist refreshed cookies) → 401.- // IMPORTANT: only return { context } for /convex/token — returning it- // for all paths would interfere with the convex plugin's own disableRefresh- // hook for /get-session (defu merge conflict).- if (ctx.path === '/convex/token') {- ctx.query = { ...ctx.query, disableRefresh: 'true' }- return { context: ctx }- }- }),- },account: {encryptOAuthTokens: true,},+ baseURL: siteUrl,+ database: authComponent.adapter(ctx),plugins: [convex({authConfig,diff --git a/convex/http.ts b/convex/http.tsindex ca08ad93..44b9e2a5 100644--- a/convex/http.ts+++ b/convex/http.ts@@ -2,20 +2,10 @@ import { httpRouter } from 'convex/server'import { authComponent, createAuth } from './auth'-const appUrl = process.env.APP_URL || 'http://localhost:3050'-const siteUrl = process.env.CONVEX_SITE_URL!-const http = httpRouter()authComponent.registerRoutes(http, createAuth, {- cors: {- allowedOrigins: [- appUrl,- // Convex deployment origins (needed for CORS on auth HTTP actions)- siteUrl,- siteUrl.replace('.convex.site', '.convex.cloud'),- ],- },+ cors: true,})export default http