Skip to content

Commit 810e996

Browse files
committed
Fix merge error
1 parent fde4908 commit 810e996

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

coderd/userauth.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -1054,10 +1054,11 @@ func (api *API) oauthLogin(r *http.Request, params oauthLoginParams) (*http.Cook
10541054
// If you do a convert to OIDC and your email does not match, we need to
10551055
// catch this and not make a new account.
10561056
if isMergeStateString(params.State.StateString) {
1057-
err := api.convertUserToOauth(ctx, r, tx, params)
1057+
user, err = api.convertUserToOauth(ctx, r, tx, params)
10581058
if err != nil {
10591059
return err
10601060
}
1061+
params.User = user
10611062
}
10621063

10631064
if user.ID == uuid.Nil && !params.AllowSignups {
@@ -1242,13 +1243,13 @@ func (api *API) oauthLogin(r *http.Request, params oauthLoginParams) (*http.Cook
12421243

12431244
// convertUserToOauth will convert a user from password base loginType to
12441245
// an oauth login type. If it fails, it will return a httpError
1245-
func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db database.Store, params oauthLoginParams) error {
1246+
func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db database.Store, params oauthLoginParams) (database.User, error) {
12461247
user := params.User
12471248

12481249
// Trying to convert to OIDC, but the email does not match.
12491250
// So do not make a new user, just block the request.
12501251
if user.ID == uuid.Nil {
1251-
return httpError{
1252+
return database.User{}, httpError{
12521253
code: http.StatusBadRequest,
12531254
msg: fmt.Sprintf("The oidc account with the email %q does not match the email of the account you are trying to convert. Contact your administrator to resolve this issue.", params.Email),
12541255
}
@@ -1260,13 +1261,13 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
12601261
StateString: params.State.StateString,
12611262
})
12621263
if xerrors.Is(err, sql.ErrNoRows) {
1263-
return httpError{
1264+
return database.User{}, httpError{
12641265
code: http.StatusBadRequest,
12651266
msg: "No convert login request found with given state. Restart the convert process and try again.",
12661267
}
12671268
}
12681269
if err != nil {
1269-
return httpError{
1270+
return database.User{}, httpError{
12701271
code: http.StatusInternalServerError,
12711272
msg: err.Error(),
12721273
}
@@ -1288,7 +1289,7 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
12881289

12891290
// If we do not allow converting to oauth, return an error.
12901291
if !params.OauthConversionEnabled {
1291-
return httpError{
1292+
return database.User{}, httpError{
12921293
code: http.StatusForbidden,
12931294
msg: fmt.Sprintf("Incorrect login type, attempting to use %q but user is of login type %q",
12941295
params.LoginType,
@@ -1301,7 +1302,7 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
13011302
// It needs to have the correct login type information for this
13021303
// user.
13031304
if user.ID != mergeState.UserID || user.LoginType != mergeState.FromLoginType || params.LoginType != mergeState.ToLoginType {
1304-
return httpError{
1305+
return database.User{}, httpError{
13051306
code: http.StatusForbidden,
13061307
msg: fmt.Sprintf("Request to convert login type from %s to %s failed", user.LoginType, params.LoginType),
13071308
}
@@ -1316,12 +1317,12 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
13161317
UserID: user.ID,
13171318
})
13181319
if err != nil {
1319-
return httpError{
1320+
return database.User{}, httpError{
13201321
code: http.StatusInternalServerError,
13211322
msg: "Failed to convert user to new login type",
13221323
}
13231324
}
1324-
return nil
1325+
return user, nil
13251326
}
13261327

13271328
// githubLinkedID returns the unique ID for a GitHub user.

0 commit comments

Comments
 (0)