p o h a
p o h a
Explore posts from servers
DTDrizzle Team
Created by p o h a on 7/19/2024 in #help
Foreign key reference in drizzle causes type error
In my drizzle schema, I have two tables, users and payment_history, when I try to reference the id of payment_history, it throws a type error Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.. users table and payment_history table have a one to many relation where one user can have many payments. These are my schema definition: users:
export const users = pgTable("users",{
...
last_payment_id: varchar("last_payment_id").references(() => payment_history.id, { onDelete: "cascade" }),//error
...
})
export const users = pgTable("users",{
...
last_payment_id: varchar("last_payment_id").references(() => payment_history.id, { onDelete: "cascade" }),//error
...
})
payment_history:
export const payment_history = pgTable("payment_history",{
id: varchar("id").primaryKey().unique().notNull(),
...
user_id: varchar("user_id").references(() => users.id, { onDelete: "cascade" }), //fk to users.id where i get type error
})
export const payment_history = pgTable("payment_history",{
id: varchar("id").primaryKey().unique().notNull(),
...
user_id: varchar("user_id").references(() => users.id, { onDelete: "cascade" }), //fk to users.id where i get type error
})
and these are the table relations: users:
export const userRelation = relations(users, ({ one, many }) => ({
...
payment_history: many(payment_history),
...
}))
export const paymentHistoryRelations = relations(payment_history, ({ one, many }) => ({
...
last_payment: one(users, {
fields: [payment_history.user_id],
references: [users.last_payment_id],
}),
...
}))
export const userRelation = relations(users, ({ one, many }) => ({
...
payment_history: many(payment_history),
...
}))
export const paymentHistoryRelations = relations(payment_history, ({ one, many }) => ({
...
last_payment: one(users, {
fields: [payment_history.user_id],
references: [users.last_payment_id],
}),
...
}))
10 replies
TTCTheo's Typesafe Cult
Created by p o h a on 9/9/2023 in #questions
UploadThing: Struggling to authenticate uploads
I am using uploadthing for the first time. I wanted to authenticate a passkey in the middleware after I upload the image.
<form className="flex flex-col gap-10 backdrop-blur-sm bg-neutral-400/10 max-w-fit p-5 place-self-center mt-10 rounded-lg border border-slate-500/50">
<input
type="text"
placeholder="Title (optional)"
className="outline-none bg-transparent border-b py-2 border-slate-300/25"
/>

<input
type="password"
placeholder="Passkey"
className="outline-none bg-transparent border-b py-2 border-slate-300/25"
/>

<UploadDropzone
endpoint="imageUploader"
onClientUploadComplete={(res) => {
// Do something with the response
console.log("Files: ", res);
alert("Upload Completed");
}}
onUploadError={(error: Error) => {
// Do something with the error.
alert(`ERROR! ${error.message}`);
}}
className="border border-dashed border-slate-300/25 rounded-md p-5"
appearance={{
button: "bg-black",
label: "Upload",

}}
config={{ mode: "manual" }}
content={{
label: "Upload (morally optional)",
}}
onUploadBegin={()=>{

}}
/>
</form>
<form className="flex flex-col gap-10 backdrop-blur-sm bg-neutral-400/10 max-w-fit p-5 place-self-center mt-10 rounded-lg border border-slate-500/50">
<input
type="text"
placeholder="Title (optional)"
className="outline-none bg-transparent border-b py-2 border-slate-300/25"
/>

<input
type="password"
placeholder="Passkey"
className="outline-none bg-transparent border-b py-2 border-slate-300/25"
/>

<UploadDropzone
endpoint="imageUploader"
onClientUploadComplete={(res) => {
// Do something with the response
console.log("Files: ", res);
alert("Upload Completed");
}}
onUploadError={(error: Error) => {
// Do something with the error.
alert(`ERROR! ${error.message}`);
}}
className="border border-dashed border-slate-300/25 rounded-md p-5"
appearance={{
button: "bg-black",
label: "Upload",

}}
config={{ mode: "manual" }}
content={{
label: "Upload (morally optional)",
}}
onUploadBegin={()=>{

}}
/>
</form>
How do i pass the passkey to the upload request to then be authenticated in the middleware
export const imageFileRouter = {
imageUploader: f({ image: { maxFileSize: "4MB" } })
.middleware(async ({ req }) => {
const { passkey } = req.body.json()
if authenticatePasskey(passkey) throw new Error("error")
})
.onUploadComplete(async ({ metadata, file }) => {
console.log("file url", file.url);
}),
} satisfies FileRouter;
export const imageFileRouter = {
imageUploader: f({ image: { maxFileSize: "4MB" } })
.middleware(async ({ req }) => {
const { passkey } = req.body.json()
if authenticatePasskey(passkey) throw new Error("error")
})
.onUploadComplete(async ({ metadata, file }) => {
console.log("file url", file.url);
}),
} satisfies FileRouter;
Something like this
8 replies