-
Notifications
You must be signed in to change notification settings - Fork 74
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
Error: tokens can only be created server-side using the API Secret #665
Comments
This should be working fine. Are you sure that your .env file is being accessed properly? Can you try to console.log your app key and secret and make sure they're being found. If so, let me know, and we'll dig further. |
Yes, the key and secret are called correctly. I found the issue and a temporary workaround. The error is being thrown because the client.secret is undefined in the instance, even though it's passed with the getInstance() function. Here's how I'm handling it:
|
Next.js doesn't have process.env as standard, that might be the issue. We should handle it better /cc @mahboubii @vishalnarkhede Docs:
src: https://nextjs.org/docs/basic-features/environment-variables |
@emeka100 Do you happen to call |
In this SDK the |
i am getting exactly the same issue when used with the api routes. Tried commenting out all the client-side code just in case something affects it but it seems that the instance still has an undefined secret. Even if i hard code the value. Using the Also if getInstance only creates 1 instance for all the runtime, then if we have an instance initialized inside an Thanks! |
Replying back with an answer to the problem. Just use Hope this helps @emeka100 |
@kyriacos You are right. Alternatively, you can simply use |
I am still getting error on this |
Hi Rohan, your issue is not related to this. Can you please follow up on the tickets from support@getstream.io. GitHub issues are reserved for bug reports and feature requests/improvements. Your issue is not a bug, just implementation. |
I am having the same error event after using
|
Anyone got a fix for this? I have the same problem.. |
- const serverClient = new StreamChat.getInstance(key, secret);
+ const serverClient = StreamChat.getInstance(key, secret); |
@ferhatelmas That did not fix the issue for me, its a deeper problem with how the stream-chat module works, if you look at the node-modules you see:
You have to make sure that the first call to StreamChat.getInstance happens on the server, in my case I had to make sure all frontend component references to StreamChat.getInstance(key) do a pre render call to the server first to create the initial instance. |
Good to hear you were able to solve the issue. Your explanation sounds correct to me. It's just a convenience to prevent multiple connection from the same client (on sloppy implementations such as creating an instance in each render). In advanced usage, instance could be created by yourself ( |
const stream = require('getstream'); require('dotenv').config(); const api_key = process.env.STREAM_API_KEY; const signup = async (req, res) => {
}; const login = async (req, res) => {
}; module.exports = { signup, login } Can anyone solve the error |
Also have the issue, any solution yet? |
This worked for me. |
ERROR Error: tokens can only be created server-side using the API Secret |
is you solved this error? |
i have this error when i try to create a user : |
Hi , Where you able to solve this error: i have the same error: --------ERROR----------- |
This is working fine for me now.
const streamClient = connect(
process.env.STREAM_API_KEY as string,
process.env.STREAM_SECRET_KEY as string,
undefined,
{ browser: false, location: "us-east"} // <-- added option for browser mode false
)
const userToken = streamClient.createUserToken(userId)
res.status(200).json({ data: userToken }) |
I'm running an api server using nextjs api routes, which is basically a backend server: https://nextjs.org/docs/api-routes/introduction
However, I'm getting this error when initiating client.createToken()
Error: tokens can only be created server-side using the API Secret
Here's my code below :
`
import { StreamChat } from 'stream-chat'
const client = StreamChat.getInstance(process.env.STREAM_KEY, process.env.STREAM_SECRET)
export default function handler(req, res) {
}
`
The text was updated successfully, but these errors were encountered: