BasicAuth fails when calling api endpoint

I want to add basic auth to my docker-compose based project.

This is my current config:

services:
  reverse-proxy:
    # The official v2 Traefik docker image
    image: traefik:v2.4
    # Enables the web UI and tells Traefik to listen to docker
    command:
      # Enabling docker provider
      - '--providers.docker'
      # Do not expose containers unless explicitly told so
      - '--providers.docker.exposedbydefault=false'
      - '--entryPoints.web.address=:${PORT}'
      - '--providers.docker.constraints=Label(`custom.label`,`${COMPOSE_PROJECT_NAME}`)'
    ports:
      # The HTTP port
      - ${PORT}:${PORT}
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - 'custom.label=${COMPOSE_PROJECT_NAME}'

  postgres:
    image: postgres:13.2
    environment:
      - POSTGRES_USER=oip
      - POSTGRES_PASSWORD=
      - POSTGRES_HOST_AUTH_METHOD=trust
    labels:
      - 'custom.label=${COMPOSE_PROJECT_NAME}'

  jhipster:
    build: ./jhipster
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/backend
    depends_on:
      - postgres
    labels:
      - 'traefik.enable=true'
      - 'traefik.http.routers.jhipster.rule=PathPrefix(`/api`)'
      - 'custom.label=${COMPOSE_PROJECT_NAME}'

  frontend:
    build: ./frontend
    depends_on:
      - jhipster
    labels:
      - 'traefik.enable=true'
      - 'traefik.http.routers.frontend.rule=PathPrefix(`/`)'
      - 'custom.label=${COMPOSE_PROJECT_NAME}'

      - 'traefik.http.middlewares.auth.basicauth.users=test:$$2y$$12$$ci.4U63YX83CwkyUrjqxAucnmi2xXOIlEF6T/KdP9824f1Rf1iyNG'
      - 'traefik.http.routers.frontend.middlewares=auth'

When accessing localhost:PORT the browser asks for the credentials and if they are valid the page is shown. But if the page then makes an request to the backend (located at /api/) the browser asks for the credentials again. But this time they are not accepted and pressing on sign in just reloads the pop up.

Any ideas?

Thanks in advance.