Jakesdoc
Jakesdoc
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Jakesdoc on 4/22/2024 in #questions
Drizzle wont push db changes to Planetscale
Every time I try to push my schema to Planetscale, I get the following error:
if (unsquashed.columns.length === 1 && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && prevSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].name === unsquashed.columns[0]) {
^

TypeError: Cannot read properties of undefined (reading 'type')
if (unsquashed.columns.length === 1 && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && prevSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].name === unsquashed.columns[0]) {
^

TypeError: Cannot read properties of undefined (reading 'type')
2 replies
TTCTheo's Typesafe Cult
Created by Jakesdoc on 4/6/2023 in #questions
User Creation With Clerk
I have an app where everyone has to have an account to access it but only admins can grant new people accounts. Users don't have the ability to request an account. Right now we are just using devise from ruby to create an account and send a password reset email on creation to avoid creating a temporary password and let them set their own on the first login. Is there a way to establish something similar in clerk?
1 replies
TTCTheo's Typesafe Cult
Created by Jakesdoc on 3/17/2023 in #questions
react-hook-form types
I'm using react-hook-form with typescript and I changed from using the useForm to the useFormContext and Typescript brought to my attention that the types of the errors are not the same. Using useForm, errors.firstName.message is of type string as I would expect, but with the context version, the type is string | FieldError | Merge<FieldError, FieldErrorsImpl<any>> | undefined. Why are these types different and how do I just get the message while using the context version?
1 replies
TTCTheo's Typesafe Cult
Created by Jakesdoc on 1/11/2023 in #questions
How to update data on a static site?
I have a site that is mostly static. I feel like astro would be fairly well suited for it. My problem is something about static sites just doesn't click with me. I see all these examples of Blogs for example. How are they adding new posts if a blog is static? Are they redeploying the entire app every time a new post is added? I have for example a few posts (not many. If things go well, there may be a few thousand) and a few users who manage those posts (again, not many. Maybe a few dozen or a couple hundred way down the line). I need to be able to go into a portal and submit a new post and have that show up without having to redeploy every time (unless there is some trick to make that happen really really fast that I don't know about. And I do have some minimal javascript required such as filtering and sorting and searching as well as analyzing metrics (how many posts there are, how many posts per user, etc.). Is there something I'm just not getting? I'm just feeling more and more like the t3 stack is overkill for what I'm doing but maybe that's just what is required for something like this?
31 replies
TTCTheo's Typesafe Cult
Created by Jakesdoc on 11/28/2022 in #questions
Error handling deeply nested writes
This post https://github.com/prisma/prisma/issues/8776 goes into pretty good detail about the issue. I'm just wondering if anyone here has a good solution for this? I have a large form to submit and on submission I have a lot of related data that gets created all at once in my database. I can't have it return an error saying unknown arg. I can't do form validation with a useless error like that. My current thought is to maybe create the new item and then update each of the related fields in separate calls to potentially get an error from each of those. Something like:
#This does not work
await prisma.user.create({
data: {
....,
post: {
connect: { id: post_id }
}
}
}

#Potential solution
const user = await prisma.user.create({
data: {
....,
}
}

await prisma.user.update({
where: {
id: user.id
},
post: {
connect: { id: post_id }
}
})
#This does not work
await prisma.user.create({
data: {
....,
post: {
connect: { id: post_id }
}
}
}

#Potential solution
const user = await prisma.user.create({
data: {
....,
}
}

await prisma.user.update({
where: {
id: user.id
},
post: {
connect: { id: post_id }
}
})
This feels really dumb though.
1 replies
TTCTheo's Typesafe Cult
Created by Jakesdoc on 11/14/2022 in #questions
Augment user type in JWT callback
I am trying to get access to user.role here, but no matter how I alter the next-auth.d.ts, it doesn't seem to change this user object.
callbacks: {
jwt: async ({ token, user }) => {
if (user) {
token.id = user.id;
// token.role = user.
}
return token;
},
session: ({ session, token }) => {
if (session.user) {
session.id = token.id;
session.user.role = token.role;
}
return session;
},
},
callbacks: {
jwt: async ({ token, user }) => {
if (user) {
token.id = user.id;
// token.role = user.
}
return token;
},
session: ({ session, token }) => {
if (session.user) {
session.id = token.id;
session.user.role = token.role;
}
return session;
},
},
Here is my next-auth.d.ts
import { DefaultSession } from "next-auth";

declare module "next-auth" {
/**
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
*/
interface Session {
id: string;
user?: {
id: string;
sponsorId?: string;
role: string;
} & DefaultSession["user"];
}
}

declare module "next-auth/jwt" {
interface JWT {
id: string;
role: string;
sponsorId?: string;
}
}
import { DefaultSession } from "next-auth";

declare module "next-auth" {
/**
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
*/
interface Session {
id: string;
user?: {
id: string;
sponsorId?: string;
role: string;
} & DefaultSession["user"];
}
}

declare module "next-auth/jwt" {
interface JWT {
id: string;
role: string;
sponsorId?: string;
}
}
4 replies
TTCTheo's Typesafe Cult
Created by Jakesdoc on 11/3/2022 in #questions
ISR in frameworks
I'm just curious, I have an application that is mostly static and doesn't need to be updated super often so I enjoy the ISR that next offers. That way I get the speed of static pages, but I can get new data when it is added. My question is, is there any other frameworks that use this feature? I didn't see anything about it mentioned in the astro docs for example (though I may have just missed it or it may be called something else there).
21 replies
TTCTheo's Typesafe Cult
Created by Jakesdoc on 9/20/2022 in #questions
Creating deeply nested Prisma entries
I am trying to create a deeply nested object in Prsima using explicit many to many and it sort of works? The problem is, it seems Prisma has 0 proper error handling at anything more than 1 level deep. For example if I have
prisma.portfolio.create({
data: {
locations: {
create: input.locations?.map((location) => ({
Location: {
connectOrCreate: {
where: { name: location?.name }
create: {
name: location?.name
contacts: {
connectOrCreate: location.contacts?.map((contact) => {
where: {
name: contact.name
}
create: {
name: "Some invalid value"
}
}
}
}
}
},
})),
},
});
prisma.portfolio.create({
data: {
locations: {
create: input.locations?.map((location) => ({
Location: {
connectOrCreate: {
where: { name: location?.name }
create: {
name: location?.name
contacts: {
connectOrCreate: location.contacts?.map((contact) => {
where: {
name: contact.name
}
create: {
name: "Some invalid value"
}
}
}
}
}
},
})),
},
});
Then, I will get an error on trying to post this but the error is something extremely inaccurate like Location is not a valid key on locations did you mean "Name"? However when I then remove the invalid key from the contacts, the code works just fine. So the problem is obviously the contact field but I get no information about what field is actually incorrect or why. Is there a way to deal with this? Right now my first thought is to possibly break out each nested create into its own separate call but I don't feel like that is right.
1 replies