punimtag/viewer-frontend/SETUP_INSTRUCTIONS.md
Tanya de2144be2a feat: Add new scripts and update project structure for database management and user authentication
This commit introduces several new scripts for managing database operations, including user creation, permission grants, and data migrations. It also adds new documentation files to guide users through the setup and configuration processes. Additionally, the project structure is updated to enhance organization and maintainability, ensuring a smoother development experience for contributors. These changes support the ongoing transition to a web-based architecture and improve overall project functionality.
2026-01-06 13:53:24 -05:00

2.1 KiB

Setup Instructions for Authentication

Follow these steps to set up authentication and create the admin user.

Step 1: Create Database Tables

Run the SQL script as a PostgreSQL superuser:

psql -U postgres -d punimtag -f setup-auth-complete.sql

Or connect to your database and run the SQL manually:

-- Connect to database
\c punimtag

-- Then run the contents of setup-auth-complete.sql

Step 2: Create Admin User

After the tables are created, run the Node.js script to create the admin user:

npx tsx scripts/create-admin-user.ts

This will create an admin user with:

  • Email: admin@admin.com
  • Password: admin
  • Role: Admin (can approve identifications)

Step 3: Regenerate Prisma Client

npx prisma generate

Step 4: Verify Setup

  1. Check tables exist:

    \dt users
    \dt pending_identifications
    
  2. Check admin user:

    SELECT email, name, is_admin FROM users WHERE email = 'admin@admin.com';
    
  3. Test registration:

  4. Test admin login:

Permission Model

  • Regular Users: Can INSERT into pending_identifications (identify faces)
  • Admin Users: Can UPDATE pending_identifications (approve/reject identifications)
  • Application Level: The isAdmin field in the User model controls who can approve

Troubleshooting

"permission denied for table users"

Make sure you've granted permissions:

GRANT SELECT, INSERT, UPDATE ON TABLE users TO viewer_write;
GRANT SELECT, INSERT, UPDATE ON TABLE pending_identifications TO viewer_write;
GRANT USAGE, SELECT ON SEQUENCE users_id_seq TO viewer_write;
GRANT USAGE, SELECT ON SEQUENCE pending_identifications_id_seq TO viewer_write;

"relation 'users' does not exist"

Run setup-auth-complete.sql first to create the tables.

"Authentication failed"

Check your .env file has correct DATABASE_URL_WRITE credentials.