adds i18n

This commit is contained in:
Christian Beutel
2024-02-29 23:26:18 +01:00
parent 528b443aa7
commit 5e19a4e8bb
45 changed files with 1520 additions and 638 deletions

View File

@@ -1,10 +1,20 @@
import { regenerateInstance } from '$lib/meilisearch'
import { pb } from '$lib/pocketbase'
import type { Handle } from '@sveltejs/kit'
import { isRouteProtected } from '$lib/util/authorization_util'
import { redirect, type Handle } from '@sveltejs/kit'
import { locale } from 'svelte-i18n'
export const handle: Handle = async ({ event, resolve }) => {
// load the store data from the request cookie string
pb.authStore.loadFromCookie(event.request.headers.get('cookie') || '')
const url = new URL(event.request.url);
// validate the user existence and if the path is acceesible
if (!pb.authStore.model && isRouteProtected(url.pathname)) {
throw redirect(302, '/login');
}
regenerateInstance();
try {
// get an up-to-date auth store state by verifying and refreshing the loaded auth model (if any)
@@ -19,6 +29,12 @@ export const handle: Handle = async ({ event, resolve }) => {
event.locals.pb = pb
event.locals.user = pb.authStore.model
const lang = pb.authStore.model?.language ?? event.request.headers.get('accept-language')?.split(',')[0]
if (lang) {
locale.set(lang)
}
const response = await resolve(event)
// send back the default 'pb_auth' cookie to the client with the latest store state