Problem with authentication over API

Hi. i started ChirpStack in docker container and tried to connect over API.
In manual I found example only for previous version JavaScript examples - ChirpStack open-source LoRaWAN® Network Server documentation

In my code, I created a connection to the default account (admin/admin) and make connection.

import * as grpc from "@grpc/grpc-js";
import { InternalServiceClient } from "@chirpstack/chirpstack-api/api/internal_grpc_pb";
import { TenantServiceClient } from "@chirpstack/chirpstack-api/api/tenant_grpc_pb";
import { GatewayServiceClient } from "@chirpstack/chirpstack-api/api/gateway_grpc_pb";
import { ListGatewaysRequest } from "@chirpstack/chirpstack-api/api/gateway_pb";
import { LoginRequest, ProfileResponse } from "@chirpstack/chirpstack-api/api/internal_pb";

async function run() {
    const url = "127.0.0.1:8080";
    const login = "admin";
    const password = "admin";
    const credentials = grpc.credentials.createInsecure();
    const internalService = new InternalServiceClient(
        url,
        grpc.credentials.createInsecure()
    );
    const loginRequest = new LoginRequest();
    loginRequest.setEmail(login);
    loginRequest.setPassword(password);
    const apiToken = await new Promise((resolve, rejects) => {
        internalService.login(loginRequest, (error, response) => {
            if (error) return rejects(error);
            if (response === undefined) return rejects("No value");
            const token = response.getJwt();
            resolve(token);
        });
    });

////const apiToken = "generate token into account"  -doesnt work

    const metadata = new grpc.Metadata();
    metadata.set("authorization", "Bearer " + apiToken);
    const gatewayService = new GatewayServiceClient(url, credentials);
    const listRequest = new ListGatewaysRequest();
    listRequest.setLimit(99);
    listRequest.setOffset(0);
    gatewayService.list(listRequest, metadata, (err, value) => {
        if (err) return console.error(err);
        console.dir(value);
        if (!value) return console.error("no value");
        console.dir(value.getResultList().map((v) => v.toObject()));
    });
}

But when I wanted to generate a token in my account (Network Server/API Keys) and establish a connection, I failed. What is the problem?

Hi @Umberto,
Can you share logs or error messages?

Hi @Jerome73 , in powershell i get next error
Error: 16 UNAUTHENTICATED

But, when i see log files in deployed docker container with chirpstack, I see this:

INFO gRPC{uri=/api.GatewayService/List}: chirpstack::api: Finished processing request status="200" latency=1.034502ms

It happens when creating an API key in the Tenant section