mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-26 11:51:17 +00:00
Compare commits
3 Commits
fix/dashbo
...
feat/admin
| Author | SHA1 | Date | |
|---|---|---|---|
|
39ced53900
|
|||
|
c1d9ec9399
|
|||
|
34214f5f3e
|
@@ -47,15 +47,10 @@ export const Route = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
id: "dashboard",
|
||||
beforeLoad: async ({ context }) => {
|
||||
let session: Awaited<ReturnType<typeof getSession>> | null = null
|
||||
try {
|
||||
session = await context.queryClient.ensureQueryData({
|
||||
queryKey: ["session"],
|
||||
queryFn: getSession,
|
||||
})
|
||||
} catch {
|
||||
throw redirect({ to: "/login" })
|
||||
}
|
||||
const session = await context.queryClient.ensureQueryData({
|
||||
queryKey: ["session"],
|
||||
queryFn: getSession,
|
||||
})
|
||||
if (!session?.user) {
|
||||
throw redirect({ to: "/login" })
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@ export function createAuth(db: Database) {
|
||||
provider: "pg",
|
||||
schema,
|
||||
}),
|
||||
advanced: {
|
||||
disableCSRFCheck: process.env.NODE_ENV !== "production",
|
||||
},
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Hono } from "hono"
|
||||
import { cors } from "hono/cors"
|
||||
|
||||
import { registerAdminHttpHandlers } from "./admin/http.ts"
|
||||
import { createRequireAdmin } from "./auth/admin-middleware.ts"
|
||||
@@ -51,34 +50,6 @@ function main() {
|
||||
|
||||
const app = new Hono()
|
||||
|
||||
const isDev = process.env.NODE_ENV !== "production"
|
||||
const allowedOrigins = process.env.CORS_ORIGINS?.split(",").map((o) => o.trim()) ?? []
|
||||
|
||||
function resolveOrigin(origin: string): string | undefined {
|
||||
if (isDev) return origin
|
||||
return allowedOrigins.includes(origin) ? origin : undefined
|
||||
}
|
||||
|
||||
app.use(
|
||||
"/api/auth/*",
|
||||
cors({
|
||||
origin: resolveOrigin,
|
||||
allowHeaders: ["Content-Type", "Authorization"],
|
||||
allowMethods: ["POST", "GET", "OPTIONS"],
|
||||
exposeHeaders: ["Content-Length"],
|
||||
maxAge: 600,
|
||||
credentials: true,
|
||||
}),
|
||||
)
|
||||
|
||||
app.use(
|
||||
"*",
|
||||
cors({
|
||||
origin: resolveOrigin,
|
||||
credentials: true,
|
||||
}),
|
||||
)
|
||||
|
||||
app.get("/health", (c) => c.json({ status: "ok" }))
|
||||
|
||||
const authSessionMiddleware = createRequireSession(auth)
|
||||
|
||||
Reference in New Issue
Block a user