Redirecting issues
Unanswered
Mugger Crocodile posted this in #help-forum
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
@Mugger Crocodile 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?
js
//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();
js
//@lib/an actions file
'use server'
export const redirectToAChat = (chatId: string) => {
console.log(`Redirected to ${chatId}`)
redirect(`/dashboard/${chatId}`)
}
check here for an explanation https://nextjs-forum.com/post/1240045719939715143#message-1240174382463324294