Access clerkId inside upload thing callback

If the uploadthing webhook callback runs on the server wouldn't it make sense that i could still use my clerk auth hooks to get the user data? My file router looks something like this:
export const ourFileRouter: FileRouter = {
csvUploader: f(["text/csv"]).onUploadComplete(async ({ metadata, file }) => {
const createdTask = await createAddTask(file.url);
if (createdTask) {
console.log("Task created");
}
console.log(JSON.stringify(file));
}),
} satisfies FileRouter;
export const ourFileRouter: FileRouter = {
csvUploader: f(["text/csv"]).onUploadComplete(async ({ metadata, file }) => {
const createdTask = await createAddTask(file.url);
if (createdTask) {
console.log("Task created");
}
console.log(JSON.stringify(file));
}),
} satisfies FileRouter;
createAddTask has this call:
export async function createAddTask(filename: string) {
const user = await getUserByClerkID();
export async function createAddTask(filename: string) {
const user = await getUserByClerkID();
getUserByClerkID:
export const getUserByClerkID = async (select = { id: true }) => {
const { userId } = auth();
const user = await prisma.user.findUniqueOrThrow({
where: {
clerkId: userId as string,
},
select,
});

return user;
};
export const getUserByClerkID = async (select = { id: true }) => {
const { userId } = auth();
const user = await prisma.user.findUniqueOrThrow({
where: {
clerkId: userId as string,
},
select,
});

return user;
};
I think it has something to do with it not running in a place where it get context about the user. Would love any heads up or pointers to where i'm making a mistake/any docs i could read for further clarification
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server