Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9dbc0c692b | |||
| b6246754e1 | |||
| be3cfa9a54 | |||
| 06e7ddaa61 | |||
| 15131b72f0 | |||
| 564fb75cc2 | |||
| 40a5ca06c8 | |||
| bc1f11a901 | |||
| f4e34f2826 |
@@ -95,7 +95,7 @@ export async function initAuth(): Promise<void> {
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
max: 10,
|
max: 10,
|
||||||
window: 60,
|
window: 60,
|
||||||
storage: "database",
|
storage: "memory",
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
genericOAuth({
|
genericOAuth({
|
||||||
@@ -234,7 +234,7 @@ export async function initAuth(): Promise<void> {
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
max: 10,
|
max: 10,
|
||||||
window: 60,
|
window: 60,
|
||||||
storage: "database",
|
storage: "memory",
|
||||||
},
|
},
|
||||||
account: {
|
account: {
|
||||||
storeStateStrategy: "cookie" as const,
|
storeStateStrategy: "cookie" as const,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { zValidator } from "@hono/zod-validator";
|
import { zValidator } from "@hono/zod-validator";
|
||||||
import { z } from "zod/v3";
|
import { z } from "zod/v3";
|
||||||
import { eq, getDb, staff, businessSettings, authProviderConfig, encryptSecret } from "@groombook/db";
|
import { and, eq, getDb, sql, staff, businessSettings, authProviderConfig, encryptSecret } from "@groombook/db";
|
||||||
import type { AppEnv } from "../middleware/rbac.js";
|
import type { AppEnv } from "../middleware/rbac.js";
|
||||||
|
|
||||||
export const setupRouter = new Hono<AppEnv>();
|
export const setupRouter = new Hono<AppEnv>();
|
||||||
@@ -108,6 +108,21 @@ setupRouter.post("/", zValidator("json", setupSchema), async (c) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!resolvedStaff && jwt.email) {
|
||||||
|
// Try auto-link by email: staff record exists with matching email but no userId
|
||||||
|
const [byEmail] = await tx
|
||||||
|
.select()
|
||||||
|
.from(staff)
|
||||||
|
.where(and(eq(staff.email, jwt.email), sql`${staff.userId} IS NULL`));
|
||||||
|
if (byEmail) {
|
||||||
|
await tx
|
||||||
|
.update(staff)
|
||||||
|
.set({ userId: jwt.sub })
|
||||||
|
.where(eq(staff.id, byEmail.id));
|
||||||
|
resolvedStaff = { ...byEmail, userId: jwt.sub };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!resolvedStaff) {
|
if (!resolvedStaff) {
|
||||||
// Brand new user during OOBE — create staff record
|
// Brand new user during OOBE — create staff record
|
||||||
if (!jwt.email) {
|
if (!jwt.email) {
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- Better-Auth rate limiting table (GRO-574)
|
||||||
|
CREATE TABLE "rate_limit" (
|
||||||
|
key TEXT NOT NULL PRIMARY KEY,
|
||||||
|
count INTEGER NOT NULL,
|
||||||
|
last_request BIGINT NOT NULL
|
||||||
|
);
|
||||||
@@ -176,6 +176,13 @@
|
|||||||
"when": 1775396067192,
|
"when": 1775396067192,
|
||||||
"tag": "0024_invoice_indexes",
|
"tag": "0024_invoice_indexes",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 25,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1775482467192,
|
||||||
|
"tag": "0025_rate_limit",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user