moved page rendering to a different service and access is now behind
admin.DOMAIN www.DOMAIN db.DOMAIN
This commit is contained in:
parent
c7f6b30b87
commit
1027da989e
126 changed files with 6356 additions and 1516 deletions
27
app-admin/src/hooks.server.ts
Normal file
27
app-admin/src/hooks.server.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { redirect, type Handle } from '@sveltejs/kit';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import { createPocketBase } from '$lib/pb';
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
event.locals.pb = createPocketBase(
|
||||
event.request.headers.get('cookie') ?? '',
|
||||
env.POCKETBASE_INTERNAL_URL
|
||||
);
|
||||
event.locals.user = event.locals.pb.authStore.record;
|
||||
|
||||
const path = event.url.pathname;
|
||||
const isLoginRoute = path === '/login';
|
||||
const isAuthed = event.locals.pb.authStore.isValid;
|
||||
|
||||
if (!isLoginRoute && !isAuthed) {
|
||||
throw redirect(303, '/login');
|
||||
}
|
||||
|
||||
if (isLoginRoute && isAuthed) {
|
||||
throw redirect(303, '/pages');
|
||||
}
|
||||
|
||||
const response = await resolve(event);
|
||||
response.headers.append('set-cookie', event.locals.pb.authStore.exportToCookie({ sameSite: 'lax' }, 'pb_auth'));
|
||||
return response;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue