Skip to content

Commit eb8c24e

Browse files
claudfuenclaude
andcommitted
fix(admin): revert env example changes, fix stale integration query, add secure cookie tests
- Revert .env.example DATABASE_URL changes — they break existing bun docker:up workflow (out of scope for this PR) - Remove docker-compose.db.yml (related to reverted env changes) - Fix health endpoint: include integrations with lastRunAt=null in stale count (never-run integrations are the stalest) - Add tests for __Secure- cookie prefix fallback in CLI callback Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7083eb3 commit eb8c24e

File tree

8 files changed

+35
-26
lines changed

8 files changed

+35
-26
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Required
22
AUTH_SECRET="" # openssl rand -base64 32
3-
DATABASE_URL="" # Format: "postgresql://comp:comp@127.0.0.1:5435/comp_dev"
3+
DATABASE_URL="" # Format: "postgresql://postgres:pass@127.0.0.1:5432/comp"
44
RESEND_DOMAIN="" # Domain configured in Resend, e.g. mail.trycomp.ai
55
RESEND_API_KEY="" # API key from Resend for email authentication / invites
66
RESEND_FROM_MARKETING=""

apps/api/src/admin/admin-org.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ export class AdminOrgService {
8282
db.integration.count({
8383
where: {
8484
organizationId: orgId,
85-
lastRunAt: { lt: new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000) },
85+
OR: [
86+
{ lastRunAt: null },
87+
{ lastRunAt: { lt: new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000) } },
88+
],
8689
},
8790
}),
8891
db.vendor.count({ where: { organizationId: orgId } }),

apps/app/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ AUTH_GOOGLE_ID="" # Google login
44
AUTH_GOOGLE_SECRET="" # Google Login
55
AUTH_GITHUB_ID="" # Optional
66
AUTH_GITHUB_SECRET="" # Optional
7-
DATABASE_URL="postgresql://comp:comp@localhost:5435/comp_dev" # Should be the default
7+
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/comp" # Should be the default
88
AUTH_SECRET="" # Used for auth, use something random and strong
99
SECRET_KEY="" # Used for encrypting data, use something random and strong
1010
NEXT_PUBLIC_BETTER_AUTH_URL=http://localhost:3000 # Must point to the domain hosting the app

apps/app/.env.test.local.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ E2E_TEST_EMAIL=e2e-test@example.com
66
E2E_TEST_NAME=E2E Test User
77

88
# Database (adjust as needed)
9-
DATABASE_URL="postgresql://comp:comp@localhost:5435/comp_dev?schema=public"
9+
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/comp?schema=public"
1010

1111
# Required app vars
1212
AUTH_SECRET=test-secret-for-e2e-only

apps/app/src/app/api/cli/callback/route.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,32 @@ describe('CLI callback route', () => {
7979
expect(res.status).toBe(400);
8080
});
8181

82+
it('should prefer __Secure- prefixed cookie for HTTPS environments', async () => {
83+
const req = createRequest(
84+
{ port: '8417' },
85+
{ '__Secure-better-auth.session_token': 'secure-token-456' },
86+
);
87+
88+
const res = await GET(req);
89+
90+
expect(res.status).toBe(307);
91+
const location = res.headers.get('location') ?? '';
92+
expect(location).toContain('token=secure-token-456');
93+
});
94+
95+
it('should fall back to unprefixed cookie when __Secure- is absent', async () => {
96+
const req = createRequest(
97+
{ port: '8417' },
98+
{ 'better-auth.session_token': 'plain-token-789' },
99+
);
100+
101+
const res = await GET(req);
102+
103+
expect(res.status).toBe(307);
104+
const location = res.headers.get('location') ?? '';
105+
expect(location).toContain('token=plain-token-789');
106+
});
107+
82108
it('should return 401 when session cookie is missing', async () => {
83109
const req = createRequest({ port: '8417' });
84110

apps/portal/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RESEND_API_KEY="" # https://resend.com/api-keys
55
RESEND_DOMAIN="" # ex. mail.trycomp.ai
66

77
# Database
8-
DATABASE_URL="" # Format: postgresql://comp:comp@localhost:5435/comp_dev
8+
DATABASE_URL="" # Format: postgresql://user:password@host:port/database
99

1010
# Public
1111
NEXT_PUBLIC_BETTER_AUTH_URL="" # http://localhost:30001

docker-compose.db.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/db/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Database connection URL for local development
2-
DATABASE_URL="" # Format: "postgresql://comp:comp@127.0.0.1:5435/comp_dev"
2+
DATABASE_URL="" # Format: "postgresql://postgres:pass@127.0.0.1:5432/comp"

0 commit comments

Comments
 (0)