HansGabriel
HansGabriel
Explore posts from servers
TTCTheo's Typesafe Cult
Created by HansGabriel on 5/3/2023 in #questions
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?
5 replies
TTCTheo's Typesafe Cult
Created by HansGabriel on 12/22/2022 in #questions
How to setup and teardown database records when running integration tests with trpc?
Currently, I'm doing this but it seems impractical to do with more tables in the database. Is there an alternative approach?
afterEach(async () => {
const ctx = await createContextInner({
session: null,
});

await ctx.prisma.record.deleteMany();
// more records here...
});
afterEach(async () => {
const ctx = await createContextInner({
session: null,
});

await ctx.prisma.record.deleteMany();
// more records here...
});
I also run into errors where certain tables still contain records which means it's not cleaned up properly after running tests. Thanks in advanced! ❤️
3 replies
TTCTheo's Typesafe Cult
Created by HansGabriel on 10/31/2022 in #questions
Mocked unit tests or Integration tests
When running tests in the frontend that involves a server side call, do you prefer to mock the server side call to do the unit tests or do you skip that and proceed with writing Integration/E2E tests?
3 replies
TTCTheo's Typesafe Cult
Created by HansGabriel on 10/30/2022 in #questions
How to increase 1mb upload limit
3 replies
TTCTheo's Typesafe Cult
Created by HansGabriel on 9/22/2022 in #questions
DB seeding
Will there be any plans to add a db seeding template to the T3 stack? Perhaps a script file that users can edit and run a db seed script to populate the database? Thanks!
18 replies