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.
2.1 KiB
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
-
Check tables exist:
\dt users \dt pending_identifications -
Check admin user:
SELECT email, name, is_admin FROM users WHERE email = 'admin@admin.com'; -
Test registration:
- Go to http://localhost:3001/register
- Create a new user account
- Verify it appears in the database
-
Test admin login:
- Go to http://localhost:3001/login
- Login with admin@admin.com / admin
Permission Model
- Regular Users: Can INSERT into
pending_identifications(identify faces) - Admin Users: Can UPDATE
pending_identifications(approve/reject identifications) - Application Level: The
isAdminfield 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.