Clerk currentuser() not working in NextJs server actions
here I got this function
export async function getYoutubeTranscript(videoId: string) {
const user = await currentUser();
if (!user?.id) {
console.log("❌ Error: User not found");
throw new Error("User not found");
}
const existingTranscript = await convex.query(
api.transcript.getTranscriptByVideoId,
{ videoId, userId: user.id }
);
if (existingTranscript) {
return {
cache:
"This video has already been transcribed - Accessing cached transcript instead of using a token",
transcript: existingTranscript.transcript,
};
}
try {
const transcript = await fetchTranscript(videoId);
await convex.mutation(api.transcript.storeTranscript, {
videoId,
userId: user.id,
transcript,
});
await client.track({
event: featureFlagEvents[FeatureFlag.TRANSCRIPTION].event,
company: {
id: user.id,
},
user: {
id: user.id,
},
});
return {
transcript,
cache:
"This video was transcribed using a token, the transcript is now saved in the database",
};
} catch (error) {
return {
transcript: [],
cache: "Error fetching transcript, please try again later",
};
}
}
to fetch the transcript. For some reason currentUser does not work in server actions and it just returns null in the console when I check it. That blocks the entire function to be invoked. Have you guys encountered a similar error?
1
1 comment
Vusal Novruzov
2
Clerk currentuser() not working in NextJs server actions
University of Code
skool.com/universityofcode
You'll get Exclusive Lessons & Content, Badass Community Support & More here to elevate as a Dev!
Leaderboard (30-day)
Powered by