MCPcopy Create free account
hub / github.com/GetStream/fullstack-nextjs-whatsapp-clone / POST

Function POST

app/api/create-user/route.ts:4–28  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

2import { StreamChat } from "stream-chat";
3
4export async function POST(request: Request) {
5 console.log("POST /api/create-user");
6
7 // 1 get the user ID we need as a parameter
8 const requestBody = await request.json();
9 const userId = requestBody.userId;
10
11 // 2 send user ID and any other required data to Stream Chat backend
12 const apiKey = process.env.NEXT_PUBLIC_REACT_APP_STREAM_KEY || "Set API Key";
13 const apiSecret = process.env.REACT_APP_STREAM_SECRET || "Set API Secret";
14 const client = StreamChat.getInstance(apiKey, apiSecret);
15
16 // 3 generate a user token
17 const upsertResponse = await client.upsertUser({
18 id: userId,
19 role: "user",
20 });
21
22 const token = client.createToken(userId);
23
24 // URL to redirect to after sign in process completes
25 return NextResponse.json({
26 userToken: token,
27 });
28}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected