Skip to content

Commit 75870c2

Browse files
authored
fix: assign new oauth users to default org (#12145)
* fix: assign new oauth users to default org This is not a final solution, as we eventually want to be able to map to different orgs. This makes it so multi-org does not break oauth/oidc.
1 parent 2a8004b commit 75870c2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

coderd/userauth.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,14 +1342,16 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
13421342
// with OIDC for the first time.
13431343
if user.ID == uuid.Nil {
13441344
var organizationID uuid.UUID
1345+
// Ignoring this error is a product of our unit tests. In prod this should never
1346+
// happen. Unit tests use this as a shortcut to making a new organization. We
1347+
// should really fix our unit tests and remove this.
13451348
//nolint:gocritic
1346-
organizations, _ := tx.GetOrganizations(dbauthz.AsSystemRestricted(ctx))
1347-
if len(organizations) > 0 {
1348-
// Add the user to the first organization. Once multi-organization
1349-
// support is added, we should enable a configuration map of user
1350-
// email to organization.
1351-
organizationID = organizations[0].ID
1352-
}
1349+
organization, _ := tx.GetDefaultOrganization(dbauthz.AsSystemRestricted(ctx))
1350+
1351+
// Add the user to the default organization.
1352+
// Once multi-organization we should check some configuration to see
1353+
// if we should add the user to a different organization.
1354+
organizationID = organization.ID
13531355

13541356
//nolint:gocritic
13551357
_, err := tx.GetUserByEmailOrUsername(dbauthz.AsSystemRestricted(ctx), database.GetUserByEmailOrUsernameParams{
@@ -1395,7 +1397,7 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
13951397
// All of the userauth tests depend on this being able to create
13961398
// the first organization. It shouldn't be possible in normal
13971399
// operation.
1398-
CreateOrganization: len(organizations) == 0,
1400+
CreateOrganization: organizationID == uuid.Nil,
13991401
LoginType: params.LoginType,
14001402
})
14011403
if err != nil {

0 commit comments

Comments
 (0)