Admin polish: stability fixes, schema security, consistent UI + sidebar #1
3 changed files with 27 additions and 8 deletions
|
|
@ -7,6 +7,18 @@ export const handle: Handle = async ({ event, resolve }) => {
|
|||
event.request.headers.get('cookie') ?? '',
|
||||
env.POCKETBASE_INTERNAL_URL
|
||||
);
|
||||
|
||||
// `isValid` only checks the token's expiry locally. Refresh it against
|
||||
// PocketBase so a revoked token (deleted user, changed password) logs the
|
||||
// user out instead of failing later as a 500, and so active sessions slide.
|
||||
if (event.locals.pb.authStore.isValid) {
|
||||
const collection = event.locals.pb.authStore.record?.collectionName || '_superusers';
|
||||
try {
|
||||
await event.locals.pb.collection(collection).authRefresh();
|
||||
} catch {
|
||||
event.locals.pb.authStore.clear();
|
||||
}
|
||||
}
|
||||
event.locals.user = event.locals.pb.authStore.record;
|
||||
|
||||
const path = event.url.pathname;
|
||||
|
|
@ -17,11 +29,17 @@ export const handle: Handle = async ({ event, resolve }) => {
|
|||
throw redirect(303, '/login');
|
||||
}
|
||||
|
||||
if (isLoginRoute && isAuthed) {
|
||||
if (isLoginRoute && isAuthed && event.request.method === 'GET') {
|
||||
throw redirect(303, '/pages');
|
||||
}
|
||||
|
||||
const response = await resolve(event);
|
||||
response.headers.append('set-cookie', event.locals.pb.authStore.exportToCookie({ sameSite: 'lax' }, 'pb_auth'));
|
||||
// The SDK defaults to `Secure`, which browsers drop over plain HTTP — that
|
||||
// would make login impossible with CADDY_SCHEME=http. Match the real scheme
|
||||
// (event.url comes from ORIGIN behind the proxy).
|
||||
response.headers.append(
|
||||
'set-cookie',
|
||||
event.locals.pb.authStore.exportToCookie({ sameSite: 'lax', secure: event.url.protocol === 'https:' }, 'pb_auth')
|
||||
);
|
||||
return response;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,13 +9,14 @@ export const actions: Actions = {
|
|||
|
||||
try {
|
||||
try {
|
||||
await locals.pb.admins.authWithPassword(email, password);
|
||||
await locals.pb.collection('_superusers').authWithPassword(email, password);
|
||||
} catch {
|
||||
await locals.pb.collection('users').authWithPassword(email, password);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Login failed for', email, err);
|
||||
return fail(400, { message: 'Invalid email or password.' });
|
||||
} catch {
|
||||
// One line per failed attempt; the full SDK error object is noise here.
|
||||
console.warn('Admin login failed for', email);
|
||||
return fail(400, { email, message: 'Invalid email or password.' });
|
||||
}
|
||||
|
||||
throw redirect(303, '/pages');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
services:
|
||||
pocketbase:
|
||||
image: spectado/pocketbase:latest
|
||||
image: docker.io/spectado/pocketbase:latest
|
||||
container_name: massage-pocketbase
|
||||
restart: unless-stopped
|
||||
# Internal only — accessed via the caddy reverse proxy
|
||||
|
|
@ -73,7 +73,7 @@ services:
|
|||
- "3000"
|
||||
|
||||
caddy:
|
||||
image: caddy:2-alpine
|
||||
image: docker.io/library/caddy:2-alpine
|
||||
container_name: massage-caddy
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue