0

import { client } from "./stream";

export default async function handler(

) { try {

    try {
        - await client.upsertUser({
            username: username as string,
            id: user_id as string,
            image: image as string,
        });
    } catch (error) {
        console.error("Error upserting user:", error);
        return res.status(500).json({ error: "Error upserting user" });
    }

    try {
        const token = client.createToken(user_id as string);
        return res.status(200).json({ token });
    } catch (error) {
        console.error("Error creating token:", error);
        return res.status(500).json({ error: "Error creating token" });
    }
} catch (error) {
    console.error("Internal server error:", error);
    return `res.status(500).json({ error: "Internal server error" });`
}

}`

I am trying to create a user in Stream Chat, and I have followed their documentation. However, when I attempt to create the user, this error is being thrown.

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 19 '23 at 23:56

1 Answers1

0

first you should create client then call createUserToken below code is working in server side.

const client = connect(API_KEY, API_SECRET, APP_ID)
        const userToken = client.createUserToken(userId)