Skip to content

Commit 09687f7

Browse files
committed
fix(auth): disable runtime schema validation on D1 and sync Gmail OAuth secret
1 parent 4e65402 commit 09687f7

3 files changed

Lines changed: 43 additions & 6 deletions

File tree

‎.github/workflows/deploy-workers.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ jobs:
7575
if [ -n "$GOOGLE_REFRESH_TOKEN" ]; then
7676
echo "$GOOGLE_REFRESH_TOKEN" | pnpm --filter @codingcatdev/site exec wrangler secret put GOOGLE_REFRESH_TOKEN --env=""
7777
fi
78+
if [ -n "$GOOGLE_WORKSPACE_REFRESH_TOKEN" ]; then
79+
echo "$GOOGLE_WORKSPACE_REFRESH_TOKEN" | pnpm --filter @codingcatdev/site exec wrangler secret put GOOGLE_WORKSPACE_REFRESH_TOKEN --env=""
80+
fi
7881
env:
7982
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
8083
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
@@ -87,6 +90,7 @@ jobs:
8790
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
8891
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
8992
GOOGLE_REFRESH_TOKEN: ${{ secrets.GOOGLE_REFRESH_TOKEN }}
93+
GOOGLE_WORKSPACE_REFRESH_TOKEN: ${{ secrets.GOOGLE_WORKSPACE_REFRESH_TOKEN }}
9094

9195
deploy-production:
9296
if: github.ref == 'refs/heads/main'
@@ -149,6 +153,9 @@ jobs:
149153
if [ -n "$GOOGLE_REFRESH_TOKEN" ]; then
150154
echo "$GOOGLE_REFRESH_TOKEN" | pnpm --filter @codingcatdev/site exec wrangler secret put GOOGLE_REFRESH_TOKEN --env production
151155
fi
156+
if [ -n "$GOOGLE_WORKSPACE_REFRESH_TOKEN" ]; then
157+
echo "$GOOGLE_WORKSPACE_REFRESH_TOKEN" | pnpm --filter @codingcatdev/site exec wrangler secret put GOOGLE_WORKSPACE_REFRESH_TOKEN --env production
158+
fi
152159
env:
153160
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
154161
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
@@ -161,3 +168,4 @@ jobs:
161168
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
162169
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
163170
GOOGLE_REFRESH_TOKEN: ${{ secrets.GOOGLE_REFRESH_TOKEN }}
171+
GOOGLE_WORKSPACE_REFRESH_TOKEN: ${{ secrets.GOOGLE_WORKSPACE_REFRESH_TOKEN }}

‎apps/site/src/lib/auth.ts‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ export async function ensureDefaultUserAndSession(db: D1Database) {
105105
"updatedAt" integer NOT NULL
106106
)`,
107107
),
108+
db.prepare(
109+
`CREATE TABLE IF NOT EXISTS "jwks" (
110+
"id" text PRIMARY KEY NOT NULL,
111+
"publicKey" text NOT NULL,
112+
"privateKey" text NOT NULL,
113+
"createdAt" integer NOT NULL,
114+
"expiresAt" integer
115+
)`,
116+
),
108117
db
109118
.prepare(
110119
`INSERT OR IGNORE INTO user (id, name, email, emailVerified, createdAt, updatedAt)
@@ -155,9 +164,8 @@ function resolveSocialProviders() {
155164
return providers;
156165
}
157166

158-
function buildAuthPlugins(origin: string) {
167+
function buildPortalAuthPlugins() {
159168
return [
160-
jwt(),
161169
emailOTP({
162170
otpLength: 6,
163171
expiresIn: 300,
@@ -257,6 +265,13 @@ function buildAuthPlugins(origin: string) {
257265
});
258266
},
259267
}),
268+
];
269+
}
270+
271+
function buildMcpAuthPlugins(origin: string) {
272+
return [
273+
jwt(),
274+
...buildPortalAuthPlugins(),
260275
mcp({
261276
resource: `${origin}/mcp`,
262277
resources: [`${origin}/mcp`, origin],
@@ -295,11 +310,20 @@ export function getAuth(origin: string, d1?: D1Database) {
295310
trustedOrigins: [
296311
"https://codingcat.dev",
297312
"https://dev.codingcat.dev",
313+
"https://postiz.codingcat.dev",
298314
origin,
299315
],
300316
...(db ? { database: db } : {}),
317+
advanced: {
318+
database: {
319+
validateSchema: false,
320+
},
321+
},
322+
account: {
323+
skipStateCookieCheck: true,
324+
},
301325
socialProviders: resolveSocialProviders(),
302-
plugins: buildAuthPlugins(origin),
326+
plugins: buildMcpAuthPlugins(origin),
303327
});
304328

305329
if (!db) {
@@ -328,10 +352,15 @@ export function getPortalAuth(origin: string, d1?: D1Database) {
328352
origin,
329353
],
330354
...(db ? { database: db } : {}),
355+
advanced: {
356+
database: {
357+
validateSchema: false,
358+
},
359+
},
331360
account: {
332361
skipStateCookieCheck: true,
333362
},
334363
socialProviders: resolveSocialProviders(),
335-
plugins: buildAuthPlugins(origin),
364+
plugins: buildPortalAuthPlugins(),
336365
});
337366
}

‎apps/site/src/pages/portal/[token].astro‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ const pageDescription = !portalFound
13141314
googleBtn.addEventListener("click", async () => {
13151315
googleBtn.setAttribute("disabled", "true");
13161316
try {
1317-
const callbackURL = window.location.pathname + window.location.hash;
1317+
const callbackURL = window.location.origin + window.location.pathname;
13181318
const res = await fetch("/api/auth/sign-in/social", {
13191319
method: "POST",
13201320
headers: { "Content-Type": "application/json" },
@@ -1415,7 +1415,7 @@ const pageDescription = !portalFound
14151415
const origText = sendMagicBtn.textContent;
14161416
sendMagicBtn.textContent = "Sending Magic Link...";
14171417
try {
1418-
const callbackURL = window.location.pathname + window.location.hash;
1418+
const callbackURL = window.location.origin + window.location.pathname;
14191419
const res = await fetch("/api/auth/sign-in/magic-link", {
14201420
method: "POST",
14211421
headers: {

0 commit comments

Comments
 (0)