(request: Request)
| 2 | import { StreamChat } from "stream-chat"; |
| 3 | |
| 4 | export 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected