Merge pull request #45 from AustinKelsay/bugfix/upgrade-already-created-user-to-admin

Add condition to allow an existing account to get admin role if they are added after the fact
This commit is contained in:
Austin Kelsay 2025-03-19 15:37:58 -05:00 committed by GitHub
commit ac56bccc5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 0 deletions

View File

@ -104,6 +104,22 @@ PlebDevs is an open-source platform that combines educational content, community
- Admin pubkey management - Admin pubkey management
- Content pricing controls - Content pricing controls
### Running locally
1. Clone the repository
2. Install dependencies
3. Create a `.env` file based on the `.env.example` file
4. Open Docker Desktop
5. Run `docker compose up --build`
6. In schema.prisma, ensure you have the local datasource uncommented and the production datasource commented out.
7. Exec into the container and run `npx prisma migrate dev`
8. Restart the docker compose
9. Rerun `docker compose up --build`
Now the database is running and the migrations are applied.
You can now run locally.
## Contributing ## Contributing
Contributions are welcome! Whether you're fixing bugs, improving documentation, or proposing new features, please feel free to open an issue or submit a PR. Contributions are welcome! Whether you're fixing bugs, improving documentation, or proposing new features, please feel free to open an issue or submit a PR.

View File

@ -50,6 +50,20 @@ const syncNostrProfile = async (pubkey) => {
await updateUser(dbUser.id, updates); await updateUser(dbUser.id, updates);
dbUser = await getUserByPubkey(pubkey); dbUser = await getUserByPubkey(pubkey);
} }
// Check if user should have author role but doesn't
if (appConfig.authorPubkeys.includes(pubkey) && !dbUser.role?.admin) {
const role = await createRole({
userId: dbUser.id,
admin: true,
subscribed: false,
});
if (role) {
await updateUser(dbUser.id, { role: role.id });
dbUser = await getUserByPubkey(pubkey);
}
}
} else { } else {
// Create new user // Create new user
const username = fields.username || pubkey.slice(0, 8); const username = fields.username || pubkey.slice(0, 8);