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

Unable to run example at all on device. StatusCode":401, #77

Closed
veyhong opened this issue Sep 3, 2020 · 6 comments
Closed

Unable to run example at all on device. StatusCode":401, #77

veyhong opened this issue Sep 3, 2020 · 6 comments

Comments

@veyhong
Copy link

veyhong commented Sep 3, 2020

 ℹ️ 🔌 already connecting
flutter: (2020-09-03 11:46:19.897330) ℹ️ 🔌 received new event: {"error":{"code":43,"message":"Connect failed with error: \"JWTAuth error: signature is not valid. Make sure the token is created using the secret for API key \"tv8e7chkfsr7\"\"","StatusCode":401,"duration":"0.00ms"}}
flutter: (2020-09-03 11:46:19.897995) ℹ️ 🔌 connection estabilished
flutter: (2020-09-03 11:46:19.898600) ℹ️ 📡 handle new event: {type: connection.changed, cid: null, connection_id: null, created_at: null, me: null, user: null, message: null, channel: null, member: null, reaction: null, total_unread_count: null, unread_channels: null, online: true, is_local: true}

gz#5725

@shodgetts
Copy link

Agent comment from Seetha in Zendesk ticket #5725:

Hi

Please let us know what are you specifically looking for. Thanks.

Cheers
Seetha

@veyhong
Copy link
Author

veyhong commented Sep 3, 2020

Hi @shodgetts thank u for replying, I am trying to run the example folder provided in this git repo.
Let me described what I did.

I got API Key from Stream dashboard, I replace in file bellow : main.dart

final client = Client(
    'my-api-key',
    logLevel: Level.INFO,
    showLocalNotification: Platform.isAndroid ? showLocalNotification : null,
    persistenceEnabled: true,
  );

  await client.setUser(
    User(id: 'super-band-9'),
    'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A',
  );

when I run using this command: flutter run -d all it did run, but I receive this 401 error stated that received new event: {"error":{"code":43,"message":"Connect failed with error: \"JWTAuth error: signature is not valid. Make sure the token is created using the secret for API key \"tv8e7chkfsr7\"\"","StatusCode":401,"duration":"0.00ms"}}

My question is where should I generate a token (how to generate this token). I do not have any back end yet.

@shodgetts
Copy link

Agent comment from Seetha in Zendesk ticket #5725:

Hi

You can generate your token using this code. This is in JS though.

const test = async () => {
    const client = new StreamChat(
      "api_key",
      "api_secret",
      { timeout: 3000 }
    );

    const token = await client.createToken("User_id");

Cheers
Seetha

@veyhong
Copy link
Author

veyhong commented Sep 3, 2020

Hi @shodgetts
Error : StreamChat not not accepting args as String, it accepting arg as widget and Client ! StreamChat(child: widget, client: client,)

new StreamChat(
      "api_key",
      "api_secret",
      { timeout: 3000 }
    )

@imtoori
Copy link
Contributor

imtoori commented Sep 3, 2020

Hi @veyhong
It's not possible to create the token using the SDK, you should create it server-side (https://getstream.io/chat/docs/tokens_and_authentication/?language=dart)
For development you can also use our token generator (https://getstream.io/chat/docs/token_generator/?language=dart)

@veyhong
Copy link
Author

veyhong commented Sep 3, 2020

Thanks @imtoori and @shodgetts , it work now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants