Make @appe.at contacts admins automatically

- is_admin() now returns true when the caller's email is on the @appe.at
  domain (in addition to the is_admin flag) — covers all admin RLS policies
  + admin-only RPCs at once.
- Backfill contacts.is_admin=true for existing @appe.at rows.
- Admin app login gate (AuthContext) mirrors the same rule so a freshly
  created @appe.at contact can sign in immediately.
This commit is contained in:
Lago committed 2026-09-09 12:58:52 +02:00
1 parent 7559f879c8
commit d341a8aa8f
2 files changed
+45 -1

No files matched your search

+7 -1
View File
@@ -12,6 +12,12 @@ interface AuthState {
const AuthContext = createContext<AuthState | null>(null);
// A contact is an admin if their `is_admin` flag is set OR their email is on
// the @appe.at domain (mirrors the DB `is_admin()` rule).
function isAdminContact(c: Contact | null): boolean {
return !!c && (c.is_admin || c.email.endsWith('@appe.at'));
}
// Load the current user's contact row. Returns null if it doesn't exist or the
// contact is not an admin (this is an admin-only app).
async function loadAdminContact(email: string): Promise<Contact | null> {
@@ -21,7 +27,7 @@ async function loadAdminContact(email: string): Promise<Contact | null> {
.eq('email', email)
.maybeSingle();
const c = data as Contact | null;
return c && c.is_admin ? c : null;
return isAdminContact(c) ? c : null;
}
export function AuthProvider({ children }: { children: ReactNode }) {