Some checks failed
CI / Backend (push) Successful in 56s
CI / UI (push) Successful in 38s
Release / Test backend (push) Successful in 42s
Release / Docker / caddy (push) Failing after 11s
CI / Backend (pull_request) Failing after 11s
Release / Docker / backend (push) Failing after 38s
CI / UI (pull_request) Successful in 44s
Release / Check ui (push) Successful in 1m53s
Release / Docker / runner (push) Failing after 1m26s
Release / Docker / ui (push) Successful in 3m46s
Release / Gitea Release (push) Has been skipped
Root cause: user_settings table was missing theme, locale, font_family, font_size columns — PocketBase silently dropped them on every save. Added the four columns via PocketBase API. Also: - listOne now sorts by -updated so the most-recent settings record wins - PARAGLIDE_LOCALE cookie is now cleared when switching back to English - pt-BR renamed to pt throughout (messages, inlang settings, validLocales) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
import { redirect } from '@sveltejs/kit';
|
|
import type { LayoutServerLoad } from './$types';
|
|
import { getSettings } from '$lib/server/pocketbase';
|
|
import { log } from '$lib/server/logger';
|
|
|
|
// Routes that are accessible without being logged in
|
|
const PUBLIC_ROUTES = new Set(['/login', '/disclaimer', '/privacy', '/dmca', '/terms', '/catalogue']);
|
|
|
|
export const load: LayoutServerLoad = async ({ locals, url, cookies }) => {
|
|
// Allow public routes, /auth/*, and all book-browsing URLs (/books/[slug] and deeper)
|
|
// Note: /books (the personal library) is intentionally NOT public
|
|
const isPublic =
|
|
PUBLIC_ROUTES.has(url.pathname) ||
|
|
url.pathname.startsWith('/auth/') ||
|
|
url.pathname.startsWith('/books/');
|
|
if (!isPublic && !locals.user) {
|
|
redirect(302, `/login`);
|
|
}
|
|
|
|
let settings = { autoNext: false, voice: 'af_bella', speed: 1.0, theme: 'amber', locale: 'en', fontFamily: 'system', fontSize: 1.0 };
|
|
try {
|
|
const row = await getSettings(locals.sessionId, locals.user?.id);
|
|
if (row) {
|
|
settings = {
|
|
autoNext: row.auto_next ?? false,
|
|
voice: row.voice ?? 'af_bella',
|
|
speed: row.speed ?? 1.0,
|
|
theme: row.theme ?? 'amber',
|
|
locale: row.locale ?? 'en',
|
|
fontFamily: row.font_family ?? 'system',
|
|
fontSize: row.font_size ?? 1.0
|
|
};
|
|
}
|
|
} catch (e) {
|
|
log.warn('layout', 'failed to load settings', { err: String(e) });
|
|
}
|
|
|
|
// If user is logged in, keep the PARAGLIDE_LOCALE cookie in sync with
|
|
// the saved locale so it persists across page loads and navigations.
|
|
if (locals.user) {
|
|
const savedLocale = settings.locale ?? 'en';
|
|
const currentCookieLocale = cookies.get('PARAGLIDE_LOCALE');
|
|
if (savedLocale === 'en') {
|
|
// Clear the cookie when the user's locale is English (the default)
|
|
if (currentCookieLocale) {
|
|
cookies.delete('PARAGLIDE_LOCALE', { path: '/' });
|
|
}
|
|
} else if (currentCookieLocale !== savedLocale) {
|
|
cookies.set('PARAGLIDE_LOCALE', savedLocale, {
|
|
path: '/',
|
|
maxAge: 34560000,
|
|
sameSite: 'lax',
|
|
httpOnly: false
|
|
});
|
|
}
|
|
}
|
|
|
|
return {
|
|
user: locals.user,
|
|
isPro: locals.isPro,
|
|
settings
|
|
};
|
|
};
|