Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamChat.createToken(id) throws TypeError: Cannot read property 'sign' of null #53

Closed
syntax-e opened this issue Aug 22, 2019 · 6 comments
Assignees
Labels
Needs More Information Further information needed from the requester

Comments

@syntax-e
Copy link

syntax-e commented Aug 22, 2019

Repro steps:

  1. Create new react native project via react-native init
  2. Add stream-chat-react-native per directions on this github repo
  3. Create new StreamChat client via const chatClient = new StreamChat(key, secret)
  4. Call chatClient.createToken(userId)

Result:

  • Throws TypeError: Cannot read property 'sign' of null on line 2848 of stream-chat/dist/browser.js
  • Debugger shows jwt is null in jwt.sign(payload, apiSecret, opts)
  • It appears var jwt = null is declared on line 2831 but is never initialized to anything

Expected:

  • Token is generated without an exception

Note:

  • The same exception is thrown when calling chatClient.devToken(userId) and subsequently calling chatClient.setUser({id, name, image})
react-native info
info 
  React Native Environment Info:
    System:
      OS: macOS 10.14.5
      CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
      Memory: 13.37 GB / 32.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.9.0 - /usr/local/bin/node
      Yarn: 1.9.4 - /usr/local/bin/yarn
      npm: 6.9.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
      Android SDK:
        API Levels: 23, 24, 25, 26, 27, 28
        Build Tools: 23.0.1, 23.0.2, 23.0.3, 24.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.3
        System Images: android-23 | Google APIs ARM EABI v7a, android-23 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom_64
    IDEs:
      Android Studio: 3.4 AI-183.6156.11.34.5692245
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      react: ^16.8.3 => 16.8.6 
      react-native: ^0.59.10 => 0.59.10 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-rename: 2.3.2
@vishalnarkhede
Copy link
Contributor

Hey @harrisonschwartz,

Client generated using secret key is only meant to be used on serverside. Seems like you are using it on clientside (on browser or mobile - react-native)

@vishalnarkhede vishalnarkhede added Needs More Information Further information needed from the requester and removed Bug Something isn't working in the SDK labels Oct 16, 2019
@vishalnarkhede
Copy link
Contributor

vishalnarkhede commented Dec 24, 2019

@syntax-e ping. Any update on this? Do you have any followup questions on this?

@vishalnarkhede
Copy link
Contributor

Closing this for now. Please reopen if you have more questions!!

@theRealSheng
Copy link

theRealSheng commented Jun 1, 2020

@vishalnarkhede how do I obtain the token by creating a user in the stream-CLI?

According to the docs:

"For development applications, it is possible to disable token authentication and use client-side generated tokens. Disabling auth checks is not suitable for a production application and should only be done for proofs-of-concept and applications in the early development stage. To enable development tokens, you need to change your application configuration."

I have also tried to use chatClient.devToken(id) and I'm getting the following error:

{
"code":5,"
StatusCode":401,
"message":"WS failed with code 5 and reason - development tokens are not allowed for this application",
"isWSFailure":false
}

Thanks in advance!

@bgeisb
Copy link

bgeisb commented Apr 18, 2021

If someone has the same problem:

The following post solved my problem:
https://stackoverflow.com/questions/62054421/how-do-i-enable-devtokens-on-getstream-io

@thechaudharysab
Copy link

thechaudharysab commented Jul 30, 2022

@vishalnarkhede I'm getting TypeError: null is not an object (evaluating 'jwt.sign') and it's because of this code:

  useEffect(() => {
    const connectStreamUser = async () => {
      try {
        await chatClient.connectUser(
          {
            id: 'talha',
            name: 'Test User'
          }, chatClient.devToken('talha'),
        );
      } catch (error) {
        console.log('----------ERROR-----------');
        console.log(err);
      }
    }

    if (!chatClient.userID) {
      console.log('------NO USER ID----------');
      connectStreamUser();
    }
  }, []);

Any solution or what I might do differently?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Information Further information needed from the requester
Projects
None yet
Development

No branches or pull requests

5 participants