title: Error: tokens can only be created server-side using the API Secret
body: <p>Its is showing an error</p>
  <p>SiteError: This method can only be used server-side using your API Secret, use client = stream.connect(key, secret)</p>
  <p>Failed to load resources : the server responded with a status of 500 (Internal Server error)</p>
  <pre><code>const stream = require('getstream');
  const bcrypt = require('bcrypt');
  const StreamChat = require('stream-chat').StreamChat;
  const crypto = require('crypto');
  require('dotenv').config();
  const api_key = process.env.STREAM_API_KEY;
  const api_secret = process.env.STREAM_API_SECRET;
  const app_id = process.env.STREAM_APP_ID;
  const signup = async (req, res) =&gt; {
  try {
  
      const { fullName, username, password, phoneNumber } = req.body;
  
      const userId = crypto.randomBytes(16).toString('hex');
  
      const serverClient = stream.connect(api_key, api_secret, app_id);
  
      const hashedPassword = await bcrypt.hash(password, 10);
  
      const token = serverClient.createUserToken(userId);
  
      res.status(200).json({ token, fullName, username, userId, hashedPassword, phoneNumber });
  } catch (error) {
      console.log(error);
  
      res.status(500).json({ message: error });
  }};
  
  const login = async (req, res) =&gt; {
  try {
      
  
      const { username, password } = req.body;
      
      const serverClient = stream.connect(api_key, api_secret, app_id);
      const client = StreamChat.getInstance(api_key, api_secret);
      if (!client.api_secret){
          client.api_secret=process.env.STREAM_API_SECRET
      }
  
      const { users } = await client.queryUsers({ name: username });
  
      if(!users.length) return res.status(400).json({ message: 'User not found' });
  
      const success = await bcrypt.compare(password, users[0].hashedPassword);
  
      const token = serverClient.createUserToken(users[0].id);
  
      if(success) {
          res.status(200).json({ token, fullName: users[0].fullName, username, userId: users[0].id});
      } else {
          res.status(500).json({ message: 'Incorrect password' });
      }
  } catch (error) {
      console.log(error);
  
      res.status(500).json({ message: error });
     } };
     module.exports = { signup, login }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/rJGgM.png" rel="nofollow noreferrer">Error while running in server</a></p>