How to use next-auth/clerk.js for getting user session

/** server/uploadthing.ts */
import { createFilething, type FileRouter } from "uploadthing/server";
const f = createFilething();

const auth = (req: Request) => ({ id: "fakeId" }); // Fake auth function

// FileRouter for your app, can contain multiple FileRoutes
export const ourFileRouter = {
// Define as many FileRoutes as you like, each with a unique routeSlug
imageUploader: f
// Set permissions and file types for this FileRoute
.fileTypes(["image", "video"])
.maxSize("1GB")
.middleware(async (req) => {
// This code runs on your server before upload
const user = await auth(req);

// If you throw, the user will not be able to upload
if (!user) throw new Error("Unauthorized");

// Whatever is returned here is accessible in onUploadComplete as `metadata`
return { userId: user.id };
})
.onUploadComplete(async ({ metadata }) => {
// This code RUNS ON YOUR SERVER after upload
console.log("Upload complete for userId:", metadata.userId);
}),
} satisfies FileRouter;

export type OurFileRouter = typeof ourFileRouter;
/** server/uploadthing.ts */
import { createFilething, type FileRouter } from "uploadthing/server";
const f = createFilething();

const auth = (req: Request) => ({ id: "fakeId" }); // Fake auth function

// FileRouter for your app, can contain multiple FileRoutes
export const ourFileRouter = {
// Define as many FileRoutes as you like, each with a unique routeSlug
imageUploader: f
// Set permissions and file types for this FileRoute
.fileTypes(["image", "video"])
.maxSize("1GB")
.middleware(async (req) => {
// This code runs on your server before upload
const user = await auth(req);

// If you throw, the user will not be able to upload
if (!user) throw new Error("Unauthorized");

// Whatever is returned here is accessible in onUploadComplete as `metadata`
return { userId: user.id };
})
.onUploadComplete(async ({ metadata }) => {
// This code RUNS ON YOUR SERVER after upload
console.log("Upload complete for userId:", metadata.userId);
}),
} satisfies FileRouter;

export type OurFileRouter = typeof ourFileRouter;
The current docs used a mock function for getting the user session. How might this be integrated with the t3 stack?
2 Replies
KiKo
KiKo2y ago
last news I received was that it currently doesnt work, and they are working on a fix https://discord.com/channels/966627436387266600/1102510616326967306/1103092338722607165
HansGabriel
HansGabriel2y ago
Ok thanks
Want results from more Discord servers?
Add your server