feat(api): Redirect browsers to frontend when accessing raw Lysand objects

This commit is contained in:
Jesse Wierzbinski 2024-07-21 22:37:12 +02:00
parent cf5684cf26
commit 757eb835e9
No known key found for this signature in database

View file

@ -1,5 +1,5 @@
import { applyConfig, handleZodError } from "@/api";
import { errorResponse, jsonResponse, response } from "@/response";
import { errorResponse, jsonResponse, redirect, response } from "@/response";
import type { Hono } from "@hono/hono";
import { zValidator } from "@hono/zod-validator";
import { z } from "zod";
@ -58,6 +58,11 @@ export default (app: Hono) =>
});
}
// Try to detect a web browser and redirect to the user's profile page
if (context.req.header("user-agent")?.includes("Mozilla")) {
return redirect(user.toApi().url);
}
return jsonResponse(user.toLysand());
},
);