From 757eb835e9af159dca7c6cd0dada81705dbd59aa Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Sun, 21 Jul 2024 22:37:12 +0200 Subject: [PATCH] feat(api): :sparkles: Redirect browsers to frontend when accessing raw Lysand objects --- server/api/users/:uuid/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/api/users/:uuid/index.ts b/server/api/users/:uuid/index.ts index 9bba0b41..19852ed8 100644 --- a/server/api/users/:uuid/index.ts +++ b/server/api/users/:uuid/index.ts @@ -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()); }, );