feat: add subscription plans. Add admin panel. Add password recovery

This commit is contained in:
Jose Selesan
2026-10-24 18:31:55 -03:00
parent f5e77c99f6
commit cd82a1e549
42 changed files with 2017 additions and 5 deletions

View File

@@ -0,0 +1,39 @@
import type { MiddlewareHandler } from 'hono';
import type { BackendEnv } from '@/http/env';
import { forbiddenProblem } from '@/http/problem-builders';
import { problemJson, unauthorizedProblem } from '@/http/problem-details';
/**
* The backoffice is for Gruperly's own staff, listed by email in `ADMIN_EMAILS`
* (comma separated, case-insensitive). An empty or missing list means nobody.
*/
export function isAdminEmail(
email: string | null | undefined,
env: Record<string, string | undefined> = process.env,
): boolean {
if (!email) return false;
const allowed = (env.ADMIN_EMAILS ?? '')
.split(',')
.map((entry) => entry.trim().toLowerCase())
.filter(Boolean);
return allowed.includes(email.trim().toLowerCase());
}
export function adminOnlyMiddleware(
env: Record<string, string | undefined> = process.env,
): MiddlewareHandler<BackendEnv> {
return async (c, next) => {
const user = c.get('user');
if (!user) return problemJson(c, unauthorizedProblem(c.req.path));
if (!isAdminEmail(user.email, env)) {
return problemJson(
c,
forbiddenProblem({
detail: 'Solo el equipo de Gruperly puede entrar al backoffice.',
code: 'admin_required',
}),
);
}
await next();
};
}