Sistema de préstamos LabRe UABC — implementación inicial
Sistema web para gestión de préstamos de material del Laboratorio de Sistemas Computacionales de la UABC. - Backend: Supabase self-hosted, schema aislado `prestamos` con RLS, triggers de stock y audit log (supabase/migrations/0001_init.sql). - Auth: Google OAuth restringido a @uabc.edu.mx, verificado en middleware y como segunda línea en trigger de DB. - Frontend: Astro 7 (SSR con adapter Node) + React islands + Tailwind v4 con paleta UABC (primary #00723F, secondary #DD971A) bajo regla 60/30/10. - Interfaz alumno mobile-first: catálogo con filtro por categorías, solicitud de préstamos, historial personal. - Interfaz admin desktop-first: panel con KPIs, bandeja de solicitudes (aprobar/rechazar/devolver), CRUD de inventario y categorías, reportes filtrables con export CSV nativo. - Modales con `<dialog>` nativo, cero librerías de UI adicionales. - Deploy: Dockerfile multi-stage node:22-alpine + docker-compose para publicar bajo prestamos.buglabs.dev vía Cloudflare Tunnel. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { defineMiddleware } from 'astro:middleware';
|
||||
import { serverClient } from '@/lib/supabase';
|
||||
|
||||
const UABC_DOMAIN = '@uabc.edu.mx';
|
||||
const PUBLIC_ROUTES = ['/login', '/api/auth/callback', '/api/auth/signout'];
|
||||
|
||||
export const onRequest = defineMiddleware(async (context, next) => {
|
||||
const supabase = serverClient(context.cookies);
|
||||
context.locals.supabase = supabase;
|
||||
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
|
||||
if (user && !user.email?.toLowerCase().endsWith(UABC_DOMAIN)) {
|
||||
await supabase.auth.signOut();
|
||||
return context.redirect('/login?error=dominio');
|
||||
}
|
||||
|
||||
context.locals.user = user;
|
||||
context.locals.profile = null;
|
||||
|
||||
if (user) {
|
||||
const { data: profile } = await supabase
|
||||
.from('profiles')
|
||||
.select('id, email, nombre, matricula, rol')
|
||||
.eq('id', user.id)
|
||||
.maybeSingle();
|
||||
context.locals.profile = profile ?? null;
|
||||
}
|
||||
|
||||
const { pathname } = context.url;
|
||||
const isPublic = PUBLIC_ROUTES.includes(pathname);
|
||||
|
||||
if (!user && !isPublic) {
|
||||
return context.redirect('/login');
|
||||
}
|
||||
|
||||
if (user && pathname === '/login') {
|
||||
return context.redirect('/');
|
||||
}
|
||||
|
||||
if (pathname.startsWith('/admin') && context.locals.profile?.rol !== 'admin') {
|
||||
return new Response('Acceso denegado', { status: 403 });
|
||||
}
|
||||
|
||||
return next();
|
||||
});
|
||||
Reference in New Issue
Block a user