Fix operator login not showing error (#2185)

* Fix operator login not showing error

Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>

* Fix Test

Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
This commit is contained in:
Daniel Valdivia
2022-07-22 10:21:25 -07:00
committed by GitHub
parent 417ea4d481
commit 9655fc4490
4 changed files with 12 additions and 6 deletions

View File

@@ -157,7 +157,7 @@ func TestBadLogin(t *testing.T) {
response, err := client.Do(request)
assert.Equal(response.StatusCode, 500, "Login request not rejected")
assert.Equal(401, response.StatusCode, "Login request not rejected")
assert.NotNil(response, "Login response is nil")
assert.Nil(err, "Login errored out")
}

View File

@@ -30,8 +30,12 @@ export class API {
.send(data)
.then((res) => res.body)
.catch((err) => {
// if we get unauthorized, kick out the user
if (err.status === 401 && localStorage.getItem("userLoggedIn")) {
// if we get unauthorized and we are not doing login, kick out the user
if (
err.status === 401 &&
localStorage.getItem("userLoggedIn") &&
!targetURL.includes("api/v1/login")
) {
if (window.location.pathname !== "/") {
localStorage.setItem("redirect-path", window.location.pathname);
}
@@ -41,6 +45,7 @@ export class API {
window.location.href = `${baseUrl}login`;
return;
}
return this.onError(err);
});
}

View File

@@ -62,12 +62,13 @@ export const doLoginAsync = createAsyncThunk(
loginStrategyEndpoints[loginStrategy.loginStrategy] || "/api/v1/login",
loginStrategyPayload[loginStrategy.loginStrategy]
)
.then(() => {
.then((res) => {
// We set the state in redux
dispatch(userLogged(true));
if (loginStrategy.loginStrategy === loginStrategyType.form) {
localStorage.setItem("userLoggedIn", accessKey);
}
// if it's in operator mode, check the Marketplace integration
if (isOperator) {
api
.invoke("GET", "/api/v1/mp-integration/")

View File

@@ -125,7 +125,7 @@ func getLoginResponse(params authApi.LoginParams) (*models.LoginResponse, *model
// prepare console credentials
consoleCreds, err = getConsoleCredentials(lr.AccessKey, lr.SecretKey)
if err != nil {
return nil, ErrorWithContext(ctx, err, ErrInvalidLogin, err)
return nil, ErrorWithContext(ctx, ErrInvalidLogin)
}
}
@@ -135,7 +135,7 @@ func getLoginResponse(params authApi.LoginParams) (*models.LoginResponse, *model
}
sessionID, err := login(consoleCreds, sf)
if err != nil {
return nil, ErrorWithContext(ctx, err, ErrInvalidLogin, err)
return nil, ErrorWithContext(ctx, ErrInvalidLogin)
}
// serialize output
loginResponse := &models.LoginResponse{