Next.js Discord

Discord Forum

Redirecting issues

Unanswered
Mugger Crocodile posted this in #help-forum
Open in Discord
Mugger CrocodileOP
So I am using vercel ai to generate a message via a route.ts file, now in the onFinish() function, I call a server action function which uses next/navigation redirect(), which should redirect the user to another pace, but for some reasons, it does not work. But the console.log() is logged in the server's console. What should I do?

//api/chat/route.ts
const result = await streamText({
    model: google("models/gemini-1.5-flash-latest"),
    messages: convertToCoreMessages(messages),
    async onFinish(event) {
      await sendMessage({
        author: 'ai',
        chatId,
        content: event.text,
      });
      redirectToAChat(chatId)
    }
  });

  return result.toDataStreamResponse();


//@lib/an actions file
'use server'
export const redirectToAChat = (chatId: string) => {
  console.log(`Redirected to ${chatId}`)
  redirect(`/dashboard/${chatId}`)
}

1 Reply