feat(auth): assign default editor role to verified users without roles

Update bootstrap rules to grant 'editor' role to verified users
Backfill existing verified users without roles in schema.sql
Apply default role automatically during email verification
This commit is contained in:
2026-05-03 12:41:00 +08:00
parent 043ebe392a
commit b9ec8076ac
3 changed files with 34 additions and 1 deletions

View File

@@ -368,6 +368,19 @@ CROSS JOIN roles r
WHERE r.key = 'owner'
ON CONFLICT DO NOTHING;
INSERT INTO user_roles (user_id, role_id)
SELECT u.id, r.id
FROM users u
CROSS JOIN roles r
WHERE u.email_verified_at IS NOT NULL
AND r.key = 'editor'
AND NOT EXISTS (
SELECT 1
FROM user_roles ur
WHERE ur.user_id = u.id
)
ON CONFLICT DO NOTHING;
CREATE TABLE IF NOT EXISTS system_wording_keys (
key text PRIMARY KEY,
module text NOT NULL,