feat(products): add public access to findAll and findAllTags endpoints

feat(ai): enhance AI admin client with status messages for API key configuration
refactor(api): remove authorization check from products route
This commit is contained in:
Nils-Johan Gynther
2026-04-19 11:42:10 +02:00
parent 045f160655
commit 39b91d8c87
3 changed files with 17 additions and 10 deletions
+12 -3
View File
@@ -81,6 +81,11 @@ export default function AiAdminClient({ keyHint, hasKey, aiFunctions }: Props) {
<strong>MISTRAL_API_KEY är inte konfigurerad</strong> alla AI-funktioner är inaktiva tills nyckeln sätts i miljövariablerna.
</div>
)}
{hasKey && (
<div style={{ background: '#fffbeb', border: '1px solid #fde68a', borderRadius: '8px', padding: '0.75rem 1rem', marginBottom: '1rem', fontSize: '0.85rem', color: '#92400e' }}>
Status <strong>Konfigurerad</strong> innebär att API-nyckeln är satt. Om Mistral svarar med 503 är det ett tillfälligt serverfel hos Mistral inte ett konfigurationsproblem.
</div>
)}
<div style={{ display: 'grid', gridTemplateColumns: 'auto 1fr', gap: '0.5rem 1.5rem', alignItems: 'center', marginBottom: '1.25rem' }}>
<span style={{ color: '#555', fontSize: '0.9rem' }}>Status</span>
<span>
@@ -151,11 +156,15 @@ export default function AiAdminClient({ keyHint, hasKey, aiFunctions }: Props) {
<tbody>
{aiFunctions.map((fn, i) => (
<tr key={i} style={{ borderBottom: '1px solid #f3f4f6', verticalAlign: 'top', opacity: hasKey ? 1 : 0.55 }}>
<td style={{ padding: '0.65rem 0.75rem' }}>
<td style={{ padding: '0.65rem 0.75rem', whiteSpace: 'nowrap' }}>
{hasKey ? (
<span title="Aktiv — API-nyckel konfigurerad" style={{ fontSize: '1.1rem' }}></span>
<span title="API-nyckel konfigurerad" style={{ display: 'inline-flex', alignItems: 'center', gap: '0.3rem', fontSize: '0.78rem', background: '#dcfce7', color: '#166534', border: '1px solid #bbf7d0', borderRadius: '4px', padding: '2px 7px' }}>
Konfigurerad
</span>
) : (
<span title="Inaktiv — MISTRAL_API_KEY saknas" style={{ fontSize: '1.1rem' }}>🔴</span>
<span title="MISTRAL_API_KEY saknas" style={{ display: 'inline-flex', alignItems: 'center', gap: '0.3rem', fontSize: '0.78rem', background: '#fef2f2', color: '#991b1b', border: '1px solid #fecaca', borderRadius: '4px', padding: '2px 7px' }}>
Inaktiv
</span>
)}
</td>
<td style={{ padding: '0.65rem 0.75rem' }}>
+2 -7
View File
@@ -1,18 +1,13 @@
import { NextRequest, NextResponse } from 'next/server';
import { getAuthHeaders } from '../../../lib/auth-headers';
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
export async function GET(req: NextRequest) {
const authHeaders = await getAuthHeaders();
if (!authHeaders.Authorization) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
export const dynamic = 'force-dynamic';
export async function GET(req: NextRequest) {
const url = new URL(req.url);
const query = url.searchParams.toString();
const res = await fetch(`${API_BASE}/api/products${query ? `?${query}` : ''}`, {
headers: authHeaders,
cache: 'no-store',
});