Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/[locale]/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AlertCircle, Loader2, X, Info, Eye, EyeOff, LogIn, Sun, Moon, Monitor,
import { discoverOAuth, type OAuthMetadata } from "@/lib/oauth/discovery";
import { generateCodeVerifier, generateCodeChallenge, generateState } from "@/lib/oauth/pkce";
import { OAUTH_SCOPES } from "@/lib/oauth/tokens";
import { apiPath } from "@/lib/api-path";

const APP_VERSION = process.env.NEXT_PUBLIC_APP_VERSION || "0.0.0";
const GIT_COMMIT = process.env.NEXT_PUBLIC_GIT_COMMIT || "unknown";
Expand Down Expand Up @@ -232,7 +233,7 @@ export default function LoginPage() {
setOauthLoading(true);
try {
const redirectUri = `${window.location.origin}/${params.locale}/auth/callback`;
const res = await fetch('/api/auth/sso/start', {
const res = await fetch(apiPath('/api/auth/sso/start'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
Expand Down
7 changes: 4 additions & 3 deletions app/admin/auth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { useEffect, useState } from 'react';
import { Save, Loader2, RotateCcw } from 'lucide-react';
import { apiPath } from "@/lib/api-path";

interface ConfigEntry {
value: unknown;
Expand All @@ -19,7 +20,7 @@ export default function AdminAuthPage() {

async function fetchConfig() {
setLoading(true);
const res = await fetch('/api/admin/config');
const res = await fetch(apiPath('/api/admin/config'));
if (res.ok) setConfig(await res.json());
setLoading(false);
}
Expand All @@ -39,7 +40,7 @@ export default function AdminAuthPage() {
setSaving(true);
setMessage(null);

const res = await fetch('/api/admin/config', {
const res = await fetch(apiPath('/api/admin/config'), {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(edits),
Expand All @@ -57,7 +58,7 @@ export default function AdminAuthPage() {
}

async function handleRevert(key: string) {
const res = await fetch('/api/admin/config', {
const res = await fetch(apiPath('/api/admin/config'), {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key }),
Expand Down
11 changes: 6 additions & 5 deletions app/admin/branding/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { useEffect, useRef, useState } from 'react';
import { Save, Loader2, RotateCcw, ImageIcon, Upload, Trash2 } from 'lucide-react';
import { apiPath } from "@/lib/api-path";

interface ConfigEntry {
value: unknown;
Expand Down Expand Up @@ -38,7 +39,7 @@ export default function AdminBrandingPage() {

async function fetchConfig() {
setLoading(true);
const res = await fetch('/api/admin/config');
const res = await fetch(apiPath('/api/admin/config'));
if (res.ok) setConfig(await res.json());
setLoading(false);
}
Expand All @@ -58,7 +59,7 @@ export default function AdminBrandingPage() {
setSaving(true);
setMessage(null);

const res = await fetch('/api/admin/config', {
const res = await fetch(apiPath('/api/admin/config'), {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(edits),
Expand All @@ -83,7 +84,7 @@ export default function AdminBrandingPage() {
formData.append('file', file);
formData.append('slot', slot);

const res = await fetch('/api/admin/branding', {
const res = await fetch(apiPath('/api/admin/branding'), {
method: 'POST',
body: formData,
});
Expand Down Expand Up @@ -112,7 +113,7 @@ export default function AdminBrandingPage() {
async function handleDeleteUpload(slot: string) {
setMessage(null);

const res = await fetch('/api/admin/branding', {
const res = await fetch(apiPath('/api/admin/branding'), {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ slot }),
Expand All @@ -133,7 +134,7 @@ export default function AdminBrandingPage() {
}

async function handleRevert(key: string) {
const res = await fetch('/api/admin/config', {
const res = await fetch(apiPath('/api/admin/config'), {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key }),
Expand Down
3 changes: 2 additions & 1 deletion app/admin/change-password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { Lock } from 'lucide-react';
import { apiPath } from "@/lib/api-path";

export default function ChangePasswordPage() {
const router = useRouter();
Expand All @@ -28,7 +29,7 @@ export default function ChangePasswordPage() {
}

setLoading(true);
const res = await fetch('/api/admin/change-password', {
const res = await fetch(apiPath('/api/admin/change-password'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ currentPassword, newPassword }),
Expand Down
7 changes: 4 additions & 3 deletions app/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useThemeStore } from '@/stores/theme-store';
import { getActiveAccountSlotHeaders } from '@/lib/auth/active-account-slot';

import { useAuthStore } from '@/stores/auth-store';
import { apiPath } from "@/lib/api-path";

const NAV_GROUPS = [
{
Expand Down Expand Up @@ -85,7 +86,7 @@ export default function AdminLayout({ children }: { children: React.ReactNode })
async function checkAuth() {
try {
const jmapHeaders = getJmapHeaders();
const res = await fetch('/api/admin/auth', { headers: jmapHeaders });
const res = await fetch(apiPath('/api/admin/auth'), { headers: jmapHeaders });
const data = await res.json();

const stalwartAdmin = data.stalwartAdmin === true;
Expand All @@ -104,7 +105,7 @@ export default function AdminLayout({ children }: { children: React.ReactNode })

// If Stalwart admin but not yet authenticated, auto-login
if (stalwartAdmin) {
const loginRes = await fetch('/api/admin/auth', {
const loginRes = await fetch(apiPath('/api/admin/auth'), {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...jmapHeaders },
body: JSON.stringify({ stalwartAuth: true }),
Expand All @@ -122,7 +123,7 @@ export default function AdminLayout({ children }: { children: React.ReactNode })
}

async function handleLogout() {
await fetch('/api/admin/auth', { method: 'DELETE' });
await fetch(apiPath('/api/admin/auth'), { method: 'DELETE' });
router.replace('/admin/login');
}

Expand Down
3 changes: 2 additions & 1 deletion app/admin/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation';
import { Shield } from 'lucide-react';
import { useConfig } from '@/hooks/use-config';
import { useThemeStore } from '@/stores/theme-store';
import { apiPath } from "@/lib/api-path";

export default function AdminLoginPage() {
const router = useRouter();
Expand All @@ -21,7 +22,7 @@ export default function AdminLoginPage() {
setLoading(true);

try {
const res = await fetch('/api/admin/auth', {
const res = await fetch(apiPath('/api/admin/auth'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password }),
Expand Down
3 changes: 2 additions & 1 deletion app/admin/logs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { useEffect, useState, useCallback } from 'react';
import { RefreshCw } from 'lucide-react';
import type { AuditEntry } from '@/lib/admin/types';
import { apiPath } from "@/lib/api-path";

export default function AdminLogsPage() {
const [entries, setEntries] = useState<AuditEntry[]>([]);
Expand All @@ -17,7 +18,7 @@ export default function AdminLogsPage() {
const params = new URLSearchParams({ page: String(page), limit: String(limit) });
if (actionFilter) params.set('action', actionFilter);

const res = await fetch(`/api/admin/audit?${params}`);
const res = await fetch(apiPath(`/api/admin/audit?${params}`));
if (res.ok) {
const data = await res.json();
setEntries(data.entries || []);
Expand Down
5 changes: 3 additions & 2 deletions app/admin/marketplace/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { useEffect, useState, useCallback } from 'react';
import { Search, Download, Check, Loader2, Store, Puzzle, SwatchBook, Star, Filter } from 'lucide-react';
import { apiPath } from "@/lib/api-path";

interface Extension {
slug: string;
Expand Down Expand Up @@ -57,7 +58,7 @@ export default function AdminMarketplacePage() {
params.set('perPage', String(perPage));
params.set('sort', 'newest');

const res = await fetch(`/api/admin/marketplace?${params}`);
const res = await fetch(apiPath(`/api/admin/marketplace?${params}`));
if (!res.ok) {
const data = await res.json().catch(() => ({}));
setError(data.error || 'Failed to connect to extension directory');
Expand Down Expand Up @@ -95,7 +96,7 @@ export default function AdminMarketplacePage() {
setMessage(null);

try {
const res = await fetch('/api/admin/marketplace', {
const res = await fetch(apiPath('/api/admin/marketplace'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
Expand Down
17 changes: 9 additions & 8 deletions app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
import { AlertTriangle } from 'lucide-react';
import { SettingsSection, SettingItem, ToggleSwitch } from '@/components/settings/settings-section';
import type { AuditEntry } from '@/lib/admin/types';
import { apiPath } from "@/lib/api-path";

interface AdminStatus {
enabled: boolean;
Expand Down Expand Up @@ -38,13 +39,13 @@ export default function AdminDashboardPage() {

async function fetchDashboardData() {
const [statusRes, auditRes, configRes, adminConfigRes, pluginRes, themeRes, policyRes] = await Promise.all([
fetch('/api/admin/auth'),
fetch('/api/admin/audit?limit=10'),
fetch('/api/config'),
fetch('/api/admin/config'),
fetch('/api/admin/plugins').catch(() => null),
fetch('/api/admin/themes').catch(() => null),
fetch('/api/admin/policy').catch(() => null),
fetch(apiPath('/api/admin/auth')),
fetch(apiPath('/api/admin/audit?limit=10')),
fetch(apiPath('/api/config')),
fetch(apiPath('/api/admin/config')),
fetch(apiPath('/api/admin/plugins')).catch(() => null),
fetch(apiPath('/api/admin/themes')).catch(() => null),
fetch(apiPath('/api/admin/policy')).catch(() => null),
]);

if (statusRes.ok) setStatus(await statusRes.json());
Expand Down Expand Up @@ -75,7 +76,7 @@ export default function AdminDashboardPage() {

if (configData?.jmapServerUrl) {
try {
const jmapRes = await fetch('/api/config');
const jmapRes = await fetch(apiPath('/api/config'));
setJmapHealth(jmapRes.ok ? 'ok' : 'error');
} catch {
setJmapHealth('error');
Expand Down
9 changes: 5 additions & 4 deletions app/admin/plugins/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
import { useParams } from 'next/navigation';
import { Puzzle, ArrowLeft, Loader2, Eye, EyeOff } from 'lucide-react';
import Link from 'next/link';
import { apiPath } from "@/lib/api-path";

interface ConfigField {
type: 'string' | 'secret' | 'boolean' | 'number' | 'select';
Expand Down Expand Up @@ -68,8 +69,8 @@ export default function PluginConfigPage() {
setLoading(true);
try {
const [pluginsRes, configRes] = await Promise.all([
fetch('/api/admin/plugins'),
fetch(`/api/admin/plugins/${encodeURIComponent(pluginId)}/config`),
fetch(apiPath('/api/admin/plugins')),
fetch(apiPath(`/api/admin/plugins/${encodeURIComponent(pluginId)}/config`)),
]);

if (pluginsRes.ok) {
Expand Down Expand Up @@ -117,7 +118,7 @@ export default function PluginConfigPage() {

// Delete if clearing a non-required field
if (!newVal && !field.required) {
const res = await fetch(`/api/admin/plugins/${encodeURIComponent(pluginId)}/config`, {
const res = await fetch(apiPath(`/api/admin/plugins/${encodeURIComponent(pluginId)}/config`), {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key }),
Expand All @@ -130,7 +131,7 @@ export default function PluginConfigPage() {
continue;
}

const res = await fetch(`/api/admin/plugins/${encodeURIComponent(pluginId)}/config`, {
const res = await fetch(apiPath(`/api/admin/plugins/${encodeURIComponent(pluginId)}/config`), {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key, value }),
Expand Down
19 changes: 10 additions & 9 deletions app/admin/plugins/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Link from 'next/link';
import { Upload, Trash2, Power, PowerOff, AlertTriangle, Loader2, Package, Save, Shield, Lock, LockOpen, Settings } from 'lucide-react';
import type { SettingsPolicy } from '@/lib/admin/types';
import { DEFAULT_POLICY } from '@/lib/admin/types';
import { apiPath } from "@/lib/api-path";

interface PluginEntry {
id: string;
Expand Down Expand Up @@ -34,7 +35,7 @@ export default function AdminPluginsPage() {

async function fetchPolicy() {
try {
const res = await fetch('/api/admin/policy');
const res = await fetch(apiPath('/api/admin/policy'));
if (res.ok) {
const data = await res.json();
setPolicy(data);
Expand Down Expand Up @@ -73,7 +74,7 @@ export default function AdminPluginsPage() {
setSavingPolicy(true);
setMessage(null);
try {
const res = await fetch('/api/admin/policy', {
const res = await fetch(apiPath('/api/admin/policy'), {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(policy),
Expand All @@ -95,7 +96,7 @@ export default function AdminPluginsPage() {
async function fetchPlugins() {
setLoading(true);
try {
const res = await fetch('/api/admin/plugins');
const res = await fetch(apiPath('/api/admin/plugins'));
if (res.ok) setPlugins(await res.json());
} finally {
setLoading(false);
Expand All @@ -113,7 +114,7 @@ export default function AdminPluginsPage() {
formData.append('file', file);

try {
const res = await fetch('/api/admin/plugins', {
const res = await fetch(apiPath('/api/admin/plugins'), {
method: 'POST',
body: formData,
});
Expand All @@ -136,7 +137,7 @@ export default function AdminPluginsPage() {

async function togglePlugin(id: string, enabled: boolean) {
setMessage(null);
const res = await fetch('/api/admin/plugins', {
const res = await fetch(apiPath('/api/admin/plugins'), {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id, enabled }),
Expand All @@ -156,7 +157,7 @@ export default function AdminPluginsPage() {
const body: Record<string, unknown> = { id, forceEnabled };
if (forceEnabled) body.enabled = true;

const res = await fetch('/api/admin/plugins', {
const res = await fetch(apiPath('/api/admin/plugins'), {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
Expand Down Expand Up @@ -190,7 +191,7 @@ export default function AdminPluginsPage() {
}
let failed = 0;
for (const p of disabled) {
const res = await fetch('/api/admin/plugins', {
const res = await fetch(apiPath('/api/admin/plugins'), {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: p.id, enabled: true }),
Expand All @@ -216,7 +217,7 @@ export default function AdminPluginsPage() {
}
let failed = 0;
for (const p of enabled) {
const res = await fetch('/api/admin/plugins', {
const res = await fetch(apiPath('/api/admin/plugins'), {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: p.id, enabled: false }),
Expand All @@ -236,7 +237,7 @@ export default function AdminPluginsPage() {
if (!confirm(`Remove plugin "${name}"? This cannot be undone.`)) return;

setMessage(null);
const res = await fetch('/api/admin/plugins', {
const res = await fetch(apiPath('/api/admin/plugins'), {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id }),
Expand Down
Loading