Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

Admin and supervisor users created from the dashboard were being registered with the 'citizen' role, preventing sign-in due to authorization checks.

Root Cause

The web app used /api/auth/sign-up/email, which ignores the role parameter and applies Better Auth's defaultRole: 'citizen'.

Changes

API: New /api/admin/users endpoint

  • Added AdminService.createUser() using Better Auth admin plugin's createUser API which respects role parameter
  • Schema validates role enum: 'admin' | 'supervisor' | 'driver'
  • Protected by auth middleware (admin/supervisor/owner only)

Web: Updated signup action

// Before: ignores role parameter
await api.post('/api/auth/sign-up/email', { name, email, password, role });

// After: respects role parameter
await api.post('/api/admin/users', { name, email, password, role });

The fix ensures users are created with their assigned role and can authenticate successfully.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • mise.run
    • Triggering command: curl REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>bug: admin added as citizen from the dashboard</issue_title>
<issue_description>At adding an admin role, registration is possible. However at singin, toast indicates unauthorized.</issue_description>

Comments on the Issue (you are @copilot in this section)

@totallynotdavid haz pull, en el nuevo PR deberia de estar andando todo bien? @PedroRojasF Sí, me aseguré de hacer pull, ya no aparece el botón de añadir usuario. Voy a agregar un botón en la sección de Configuración @PedroRojasF Image

Al crear role tipo admin se redirecciona al signin y no se permite el acceso. Queda pendiente revisar por qué se registra como citizen en la base de datos a quien se está registrando como admin</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: totallynotdavid <20960328+totallynotdavid@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 31, 2025

Deploying limalimpia with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2179a54
Status: ✅  Deploy successful!
Preview URL: https://3ba3215f.limalimpia.pages.dev
Branch Preview URL: https://copilot-fix-admin-role-signi.limalimpia.pages.dev

View logs

Copilot AI and others added 2 commits October 31, 2025 22:52
Co-authored-by: totallynotdavid <20960328+totallynotdavid@users.noreply.github.com>
Co-authored-by: totallynotdavid <20960328+totallynotdavid@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix unauthorized error for admin role on signin Fix admin/supervisor user creation defaulting to citizen role Oct 31, 2025
Copilot finished work on behalf of totallynotdavid October 31, 2025 22:56
Copilot AI requested a review from totallynotdavid October 31, 2025 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: admin added as citizen from the dashboard

2 participants