1

I'm trying to use the client side functionality of getstream.io (specifically the feed pull and live updates) to build a stream on a native app built with react-native. When I try to initialize a client in the javascript code using a token passed from my server, I get the error:

[Error: Missing app id, which is needed to subscribe, use var client = stream.connect(key, secret, appId);]

However, when I add the secret and appId (for testing purposes, I would be very wary of deploying like this) I get the error:

[Error: You are publicly sharing your private key. Dont use the private key while in the browser.]

Is there a way to get a client version running using Expo (the Create React Native App default) without ejecting from Create React Native App?

user1522860
  • 113
  • 1
  • 6
  • Out of curiosity, how will you use this native app without putting your secret key in the application? (which we don't recommend, by the way) – iandouglas Aug 16 '17 at 22:07
  • The native app communicates with a Rails server to pass down an token from a logged in user (using stream's Ruby client) and initialize the feed variable using that. – user1522860 Aug 17 '17 at 16:12

1 Answers1

2

For security reasons you can't generate tokens client side with the JS client as that would require sharing your Api Key Secret.

The way to go is for your backend to create feed specific tokens and to send them to your client-side application.

Server side (Ruby):

require 'stream'
client = Stream::Client.new('YOUR_API_KEY', 'API_KEY_SECRET')
feed = client.feed('user', '1')
token = feed.token

Client side (JS):

client = stream.connect('YOUR_API_KEY', null, 'SITE_ID');
user1 = client.feed('user', '1', token);
Tommaso Barbugli
  • 11,781
  • 2
  • 42
  • 41
  • Tommaso- That's the setup I currently have, the missing component was the null (instead of omitted) secret. That seems to have solved it and I can now move forward. Thanks! – user1522860 Aug 22 '17 at 20:21