brocaar/chirpstack-api

Cannot read property 'createInsecure' of undefined

M-Innuss opened this issue · 0 comments

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

What happened?

As i wanted to build ChirpStack gRPC API message from client to server (with javascript), the error pops up:
TypeError: Cannot read property 'createInsecure' of undefined
at file:///.

The code is copied from https://www.npmjs.com/package/@chirpstack/chirpstack-api

I think the issue is the 'credentials', that is 'undefined'. Can someone help me to solve this problem?

What did you expect?

To run the ChirpStack gRPC API message

Could you share your log output?

The code line:
// Create the client for the 'internal' service
const internalServiceClient = new internalService.InternalServiceClient(
'localhost:8080',
grpc.credentials.createInsecure()
);

And the Output with the error:
TypeError: Cannot read property 'createInsecure' of undefined
at file:///.

Your Code

import * as grpc from 'grpc';

import * as internalService from '@chirpstack/chirpstack-api/as/external/api/internal_grpc_pb';
import * as internalMessages from '@chirpstack/chirpstack-api/as/external/api/internal_pb';

// Create the client for the 'internal' service
const internalServiceClient = new internalService.InternalServiceClient(
'localhost:8080',
grpc.credentials.createInsecure()
);

// Create and build the login request message
const loginRequest = new internalMessages.LoginRequest();

loginRequest.setUsername('username');
loginRequest.setPassword('password');

// Send the login request
internalServiceClient.login(loginRequest, (error, response) => {
// Build a gRPC metadata object, setting the authorization key to the JWT we
// got back from logging in.
const metadata = new grpc.Metadata();
metadata.set('authorization', response.getJwt());

// This metadata can now be passed for requests to APIs that require authorization
// e.g.
// deviceServiceClient.create(createDeviceRequest, metadata, callback);

});

Component Version
ChirpStack API v?.?.?