fix(find): use getUserHeaders() for Immich smart search auth
The /api/find/search handler was hard-coding `Authorization: Bearer ${currentUser?.accessToken}`. When Power Tools authenticates via `IMMICH_API_KEY` (no cookie session), `accessToken` is undefined and Immich returns 401 — which surfaces in the UI as "No results found", making the feature silently unusable in API-key deployments.
This swaps the inline header construction for the existing `getUserHeaders()` helper in `src/helpers/user.helper.ts`, which already handles both modes: `x-api-key` when `isUsingAPIKey`, `Authorization: Bearer …` otherwise.
Also adds an explicit 403 when there's no authenticated user, instead of letting the request flow forward with `Bearer undefined`.
Repro (before):
curl -X POST http://localhost:8001/api/find/search -d '{"query":"beach"}' \
→ {"assets":[],"filters":{…},"error":"Failed to fetch assets"}
After:
same request → 40 assets with embeddings matching "beach"
This commit is contained in:
@@ -4,6 +4,7 @@ import { ASSET_VIDEO_PATH } from "@/config/routes";
|
|||||||
import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
|
import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
|
||||||
import { cleanUpAsset, isFlipped } from "@/helpers/asset.helper";
|
import { cleanUpAsset, isFlipped } from "@/helpers/asset.helper";
|
||||||
import { parseFindQuery } from "@/helpers/ai.helper";
|
import { parseFindQuery } from "@/helpers/ai.helper";
|
||||||
|
import { getUserHeaders } from "@/helpers/user.helper";
|
||||||
import { person } from "@/schema";
|
import { person } from "@/schema";
|
||||||
import { Person } from "@/schema/person.schema";
|
import { Person } from "@/schema/person.schema";
|
||||||
import { inArray } from "drizzle-orm";
|
import { inArray } from "drizzle-orm";
|
||||||
@@ -16,6 +17,9 @@ export default async function search(
|
|||||||
try {
|
try {
|
||||||
const { query } = req.body;
|
const { query } = req.body;
|
||||||
const currentUser = await getCurrentUser(req);
|
const currentUser = await getCurrentUser(req);
|
||||||
|
if (!currentUser) {
|
||||||
|
return res.status(403).json({ message: "Not authenticated" });
|
||||||
|
}
|
||||||
const parsedQuery = await parseFindQuery(query as string);
|
const parsedQuery = await parseFindQuery(query as string);
|
||||||
const { personIds } = parsedQuery;
|
const { personIds } = parsedQuery;
|
||||||
|
|
||||||
@@ -32,10 +36,7 @@ export default async function search(
|
|||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({ ...parsedQuery, withExif: true }),
|
body: JSON.stringify({ ...parsedQuery, withExif: true }),
|
||||||
headers: {
|
headers: getUserHeaders(currentUser, { "Content-Type": "application/json" }),
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: `Bearer ${currentUser?.accessToken}`,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
|
|||||||
Reference in New Issue
Block a user