mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 17:11:17 +00:00
Compare commits
1 Commits
feat/dev-a
...
feat/renam
| Author | SHA1 | Date | |
|---|---|---|---|
|
e6ca1763ef
|
@@ -61,7 +61,7 @@ export async function getSessionFromHeaders(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dev/test middleware that injects a fake user and session.
|
* Test-only middleware that injects a fake user and session.
|
||||||
* Pass userId to simulate an authenticated request, or omit to get 401.
|
* Pass userId to simulate an authenticated request, or omit to get 401.
|
||||||
*/
|
*/
|
||||||
export function mockAuthSessionMiddleware(userId?: string): AuthSessionMiddleware {
|
export function mockAuthSessionMiddleware(userId?: string): AuthSessionMiddleware {
|
||||||
@@ -69,34 +69,8 @@ export function mockAuthSessionMiddleware(userId?: string): AuthSessionMiddlewar
|
|||||||
if (!userId) {
|
if (!userId) {
|
||||||
return c.json({ error: "Unauthorized" }, 401)
|
return c.json({ error: "Unauthorized" }, 401)
|
||||||
}
|
}
|
||||||
|
c.set("user", { id: userId } as AuthUser)
|
||||||
const now = new Date()
|
c.set("session", { id: "mock-session" } as AuthSession)
|
||||||
const expiresAt = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000)
|
|
||||||
|
|
||||||
const user: AuthUser = {
|
|
||||||
id: "k7Gx2mPqRvNwYs9TdLfA4bHcJeUo1iZn",
|
|
||||||
name: "Dev User",
|
|
||||||
email: "dev@aelis.local",
|
|
||||||
emailVerified: true,
|
|
||||||
image: null,
|
|
||||||
createdAt: now,
|
|
||||||
updatedAt: now,
|
|
||||||
}
|
|
||||||
|
|
||||||
const session: AuthSession = {
|
|
||||||
id: "Wt3FvBpXaQrMhD8sKjE6LcYn0gUz5iRo",
|
|
||||||
userId: "k7Gx2mPqRvNwYs9TdLfA4bHcJeUo1iZn",
|
|
||||||
token: "Vb9CxNfRm2KwQs7TjPeA5dLhYg0UoZi4",
|
|
||||||
expiresAt,
|
|
||||||
ipAddress: "127.0.0.1",
|
|
||||||
userAgent: "aelis-dev",
|
|
||||||
createdAt: now,
|
|
||||||
updatedAt: now,
|
|
||||||
}
|
|
||||||
|
|
||||||
c.set("user", user)
|
|
||||||
c.set("session", session)
|
|
||||||
|
|
||||||
await next()
|
await next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { LocationSource } from "@aelis/source-location"
|
|||||||
import { Hono } from "hono"
|
import { Hono } from "hono"
|
||||||
|
|
||||||
import { registerAuthHandlers } from "./auth/http.ts"
|
import { registerAuthHandlers } from "./auth/http.ts"
|
||||||
import { mockAuthSessionMiddleware, requireSession } from "./auth/session-middleware.ts"
|
import { requireSession } from "./auth/session-middleware.ts"
|
||||||
import { createFeedEnhancer } from "./enhancement/enhance-feed.ts"
|
import { createFeedEnhancer } from "./enhancement/enhance-feed.ts"
|
||||||
import { createLlmClient } from "./enhancement/llm-client.ts"
|
import { createLlmClient } from "./enhancement/llm-client.ts"
|
||||||
import { registerFeedHttpHandlers } from "./feed/http.ts"
|
import { registerFeedHttpHandlers } from "./feed/http.ts"
|
||||||
@@ -43,16 +43,10 @@ function main() {
|
|||||||
|
|
||||||
app.get("/health", (c) => c.json({ status: "ok" }))
|
app.get("/health", (c) => c.json({ status: "ok" }))
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV !== "production"
|
|
||||||
const authSessionMiddleware = isDev ? mockAuthSessionMiddleware("dev-user") : requireSession
|
|
||||||
|
|
||||||
if (!isDev) {
|
|
||||||
registerAuthHandlers(app)
|
registerAuthHandlers(app)
|
||||||
}
|
|
||||||
|
|
||||||
registerFeedHttpHandlers(app, {
|
registerFeedHttpHandlers(app, {
|
||||||
sessionManager,
|
sessionManager,
|
||||||
authSessionMiddleware,
|
authSessionMiddleware: requireSession,
|
||||||
})
|
})
|
||||||
registerLocationHttpHandlers(app, { sessionManager })
|
registerLocationHttpHandlers(app, { sessionManager })
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user