feat: add GOTRUE_DB_DEFAULT_ROLE with backward compatibility and tests#2467
feat: add GOTRUE_DB_DEFAULT_ROLE with backward compatibility and tests#2467nancysangani wants to merge 1 commit intosupabase:masterfrom
Conversation
|
/cc @cstockton |
There was a problem hiding this comment.
Pull request overview
This PR decouples “new user default role” from JWT configuration by introducing GOTRUE_DB_DEFAULT_ROLE (with a backward-compatible fallback to GOTRUE_JWT_DEFAULT_GROUP_NAME) and updates user creation paths to use the DB-configured default role.
Changes:
- Add
DB.DefaultRoleto configuration and defaulting logic (fallback to legacy JWT default group name, then"authenticated"). - Use
config.DB.DefaultRolewhen assigning roles during user signup and admin user creation. - Add a deprecation notice for
GOTRUE_JWT_DEFAULT_GROUP_NAMEand tests covering precedence/fallback behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/conf/configuration.go | Adds DB.DefaultRole and sets default role with legacy fallback in ApplyDefaults(). |
| internal/conf/configuration_test.go | Adds tests validating default role precedence and backward compatibility. |
| internal/api/signup.go | Assigns new users the role from config.DB.DefaultRole. |
| internal/api/admin.go | Uses config.DB.DefaultRole as the default role for admin-created users (unless overridden). |
| internal/api/api.go | Updates deprecation warning text for GOTRUE_JWT_DEFAULT_GROUP_NAME. |
| example.env | Documents the new env var and adds GOTRUE_DB_DEFAULT_ROLE. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| GOTRUE_JWT_DEFAULT_GROUP_NAME="authenticated" | ||
| GOTRUE_JWT_ADMIN_ROLES="supabase_admin,service_role" | ||
|
|
||
| # Default role assigned to newly created users | ||
| GOTRUE_DB_DEFAULT_ROLE="authenticated" |
There was a problem hiding this comment.
example.env now documents GOTRUE_DB_DEFAULT_ROLE but still sets GOTRUE_JWT_DEFAULT_GROUP_NAME. Because the old variable is deprecated (and triggers a startup warning), consider removing it from the example, or at least commenting it out / adding an explicit deprecation note so users don’t copy a deprecated setting by default.
|
@cstockton Thanks for pointing me to the contributing guidelines! I’m a bit unsure how to proceed with this change. Since it introduces a new env variable, I understand it may be considered a feature and require an RFC — but the RFC repository appears to be read-only. Could you please clarify what you’d prefer here:
I’m happy to adjust the approach accordingly — just want to align with the expected contribution process. |
|
@nancysangani I would start by opening issues to discuss if these features will be accepted by the team. Some of them would require platform changes on our side that we might not be willing to commit to. |
What kind of change does this PR introduce?
Feature (with backward compatibility)
What is the current behavior?
The default role for newly created users is derived from
GOTRUE_JWT_DEFAULT_GROUP_NAME, which is being deprecated. This couples user role assignment with JWT configuration and limits flexibility.Fixes #2359
What is the new behavior?
GOTRUE_DB_DEFAULT_ROLEGOTRUE_DB_DEFAULT_ROLEis set → it is usedGOTRUE_JWT_DEFAULT_GROUP_NAMEis set → fallback to it"authenticated"GOTRUE_JWT_DEFAULT_GROUP_NAMEAdditional context
DB.DefaultRoleexample.envto include the new variableTests
Added
TestDefaultRoleApplyDefaultsto verify:Verified locally using:
go test ./internal/conf -v