fix: improve error handling for session auth check
This commit is contained in:
@@ -28,8 +28,13 @@ async function requireSessionOrBearer(request: Request, headers: Record<string,
|
||||
if (authHeader === `Bearer ${BEARER_TOKEN}`) return;
|
||||
|
||||
// Check session
|
||||
const session = await auth.api.getSession({ headers: request.headers });
|
||||
if (!session) throw new Error("Unauthorized");
|
||||
try {
|
||||
const session = await auth.api.getSession({ headers: request.headers });
|
||||
if (session) return;
|
||||
} catch {
|
||||
// Session check failed
|
||||
}
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
|
||||
export const taskRoutes = new Elysia({ prefix: "/api/tasks" })
|
||||
|
||||
Reference in New Issue
Block a user