‘Inherit auth from parent’ type of Authorization doesn’t work

I’m using the following pre-request script for my collection:

let baseUrl = pm.variables.get("baseUrl");

const loginRequest = {
  url:  `${baseUrl}/auth/login`, 
  method: 'POST',
  header: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: {
    mode: 'urlencoded',
    urlencoded : [
      { key: 'email', value: 'test@test.com'},
      { key: 'password', value: 'password'},
    ]
  }
};

pm.collectionVariables.unset("accessToken");
pm.collectionVariables.unset("refreshToken");

pm.sendRequest(loginRequest, function (err, response) {
    var jsonResponse = response.json()
    if (response.code == 200) {
        pm.collectionVariables.set("accessToken", jsonResponse.data.access_token);
        pm.collectionVariables.set("refreshToken", jsonResponse.data.refresh_token);
    } else {
        console.error("Login error")
    }
});

and I’ve set the authorization like this:

Screenshot 2022-05-02 at 12.07.29

However, sometimes it works fine, but sometimes I get 401, I’m not sure if it’s set correctly or not. I’m using no environment. Does this look ok to you? Are there any caches I have to clear?

LE: In the request header I can see the authorization is added.