@@ -175,11 +175,12 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
175
175
}
176
176
177
177
user , roles , ok := api .loginRequest (ctx , rw , loginWithPassword )
178
+ // 'user.ID' will be empty, or will be an actual value.
179
+ aReq .UserID = user .ID
178
180
if ! ok {
179
181
// user failed to login
180
182
return
181
183
}
182
- aReq .UserID = user .ID
183
184
184
185
userSubj := rbac.Subject {
185
186
ID : user .ID .String (),
@@ -224,7 +225,7 @@ func (api *API) loginRequest(ctx context.Context, rw http.ResponseWriter, req co
224
225
httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
225
226
Message : "Internal error." ,
226
227
})
227
- return database. User {} , database.GetAuthorizationUserRolesRow {}, false
228
+ return user , database.GetAuthorizationUserRolesRow {}, false
228
229
}
229
230
230
231
// If the user doesn't exist, it will be a default struct.
@@ -233,7 +234,7 @@ func (api *API) loginRequest(ctx context.Context, rw http.ResponseWriter, req co
233
234
httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
234
235
Message : "Internal error." ,
235
236
})
236
- return database. User {} , database.GetAuthorizationUserRolesRow {}, false
237
+ return user , database.GetAuthorizationUserRolesRow {}, false
237
238
}
238
239
239
240
if ! equal {
@@ -242,7 +243,7 @@ func (api *API) loginRequest(ctx context.Context, rw http.ResponseWriter, req co
242
243
httpapi .Write (ctx , rw , http .StatusUnauthorized , codersdk.Response {
243
244
Message : "Incorrect email or password." ,
244
245
})
245
- return database. User {} , database.GetAuthorizationUserRolesRow {}, false
246
+ return user , database.GetAuthorizationUserRolesRow {}, false
246
247
}
247
248
248
249
// If password authentication is disabled and the user does not have the
@@ -251,14 +252,14 @@ func (api *API) loginRequest(ctx context.Context, rw http.ResponseWriter, req co
251
252
httpapi .Write (ctx , rw , http .StatusForbidden , codersdk.Response {
252
253
Message : "Password authentication is disabled." ,
253
254
})
254
- return database. User {} , database.GetAuthorizationUserRolesRow {}, false
255
+ return user , database.GetAuthorizationUserRolesRow {}, false
255
256
}
256
257
257
258
if user .LoginType != database .LoginTypePassword {
258
259
httpapi .Write (ctx , rw , http .StatusForbidden , codersdk.Response {
259
260
Message : fmt .Sprintf ("Incorrect login type, attempting to use %q but user is of login type %q" , database .LoginTypePassword , user .LoginType ),
260
261
})
261
- return database. User {} , database.GetAuthorizationUserRolesRow {}, false
262
+ return user , database.GetAuthorizationUserRolesRow {}, false
262
263
}
263
264
264
265
//nolint:gocritic // System needs to fetch user roles in order to login user.
@@ -267,15 +268,15 @@ func (api *API) loginRequest(ctx context.Context, rw http.ResponseWriter, req co
267
268
httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
268
269
Message : "Internal error." ,
269
270
})
270
- return database. User {} , database.GetAuthorizationUserRolesRow {}, false
271
+ return user , database.GetAuthorizationUserRolesRow {}, false
271
272
}
272
273
273
274
// If the user logged into a suspended account, reject the login request.
274
275
if roles .Status != database .UserStatusActive {
275
276
httpapi .Write (ctx , rw , http .StatusUnauthorized , codersdk.Response {
276
277
Message : "Your account is suspended. Contact an admin to reactivate your account." ,
277
278
})
278
- return database. User {} , database.GetAuthorizationUserRolesRow {}, false
279
+ return user , database.GetAuthorizationUserRolesRow {}, false
279
280
}
280
281
281
282
return user , roles , true
0 commit comments