force oauth created users to start with user role

This commit is contained in:
henrygd
2026-09-18 17:10:37 -04:00
parent db3afeabd9
commit f7fd3ef403
4 changed files with 115 additions and 0 deletions

View File

@@ -24,6 +24,17 @@ func NewUserManager(app core.App) *UserManager {
}
}
// InitializeOAuthUserRole prevents self-registration from assigning a privileged role.
func (um *UserManager) InitializeOAuthUserRole(e *core.RecordAuthWithOAuth2RequestEvent) error {
if e.IsNewRecord {
if e.CreateData == nil {
e.CreateData = make(map[string]any)
}
e.CreateData["role"] = "user"
}
return e.Next()
}
// Initialize user role if not set
func (um *UserManager) InitializeUserRole(e *core.RecordEvent) error {
if e.Record.GetString("role") == "" {