Skip to content

Commit 3f74b5a

Browse files
feat: dev-auth supports userId override for testing with real accounts
1 parent 2ccb8a3 commit 3f74b5a

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

packages/api/src/routes/dev-auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ devAuth.post("/login", async (c) => {
1414
return c.json({ error: "Not found" }, 404);
1515
}
1616

17-
const { secret } = await c.req.json<{ secret: string }>();
17+
const { secret, userId: requestedUserId } = await c.req.json<{ secret: string; userId?: string }>();
1818
if (!secret || secret !== devSecret) {
1919
return c.json({ error: "Forbidden" }, 403);
2020
}
2121

22-
const userId = "dev-test-user";
22+
const userId = requestedUserId || "dev-test-user";
2323
const jwtSecret = getJwtSecret(c.env);
2424
const token = await createToken(userId, jwtSecret);
2525

packages/web/src/App.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,13 @@ export default function App() {
127127
// Dev-token auth bypass: ?dev_token=xxx in URL
128128
const params = new URLSearchParams(window.location.search);
129129
const devToken = params.get("dev_token");
130+
const devUser = params.get("dev_user");
130131
if (devToken) {
131132
dlog.info("Auth", "Dev-token login attempt");
132133
fetch("/api/dev-auth/login", {
133134
method: "POST",
134135
headers: { "Content-Type": "application/json" },
135-
body: JSON.stringify({ secret: devToken }),
136+
body: JSON.stringify({ secret: devToken, ...(devUser ? { userId: devUser } : {}) }),
136137
})
137138
.then((r) => {
138139
if (!r.ok) throw new Error(`HTTP ${r.status}`);
@@ -142,10 +143,11 @@ export default function App() {
142143
setToken(res.token);
143144
dispatch({
144145
type: "SET_USER",
145-
user: { id: res.userId, email: "dev@botschat.test", displayName: "Dev User" },
146+
user: { id: res.userId, email: devUser ? "auxtenwpc@gmail.com" : "dev@botschat.test", displayName: devUser ? "Auxten Wang" : "Dev User" },
146147
});
147-
// Remove dev_token from URL
148+
// Remove dev_token and dev_user from URL
148149
params.delete("dev_token");
150+
params.delete("dev_user");
149151
const clean = params.toString();
150152
window.history.replaceState({}, "", window.location.pathname + (clean ? `?${clean}` : ""));
151153
dlog.info("Auth", `Dev-token login success: ${res.userId}`);

0 commit comments

Comments
 (0)