fix: return database user ID from /api/auth/me instead of Logto sub
The /me endpoint was returning auth.sub (Logto's opaque string) as the user ID, but the frontend and other API endpoints expect numeric DB IDs. This caused "can't access property 'id', w[0] is undefined" after login. Also documents Logto OIDC setup requirements (scopes, env vars) in CLAUDE.md. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import { requireAuth } from "../middleware/auth.ts";
|
||||
import {
|
||||
createApiKey,
|
||||
deleteApiKey,
|
||||
getOrCreateUser,
|
||||
listApiKeys,
|
||||
} from "../services/auth.service.ts";
|
||||
import { updateProfile } from "../services/profile.service.ts";
|
||||
@@ -23,8 +24,10 @@ const app = new Hono<Env>();
|
||||
app.get("/me", async (c) => {
|
||||
const auth = await getAuth(c);
|
||||
if (auth) {
|
||||
const db = c.get("db");
|
||||
const user = await getOrCreateUser(db, auth.sub);
|
||||
return c.json({
|
||||
user: { id: auth.sub, email: auth.email },
|
||||
user: { id: user.id, email: auth.email },
|
||||
authenticated: true,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user