Override error in React tutorial on the add userId to the database step

Before adding the userId to the schema the line
await db.insert(images).values({

presents no problems. Once I add userId to the schema it presents the expected error. Once I push the new schema to the db this error presents:
No overload matches this call.
  Overload 1 of 2, '(value: { name: string | SQL<unknown> | Placeholder<string, any>; url: string | SQL<unknown> | Placeholder<string, any>; userId: string | SQL<unknown> | Placeholder<string, any>; id?: number | ... 2 more ... | undefined; createdAt?: SQL<...> | ... 2 more ... | undefined; updatedAt?: SQL<...> | ... 3 more ... | undefined; }): PgInsertBase<...>', gave the following error.
    Type 'string | null' is not assignable to type 'string | SQL<unknown> | Placeholder<string, any>'.
      Type 'null' is not assignable to type 'string | SQL<unknown> | Placeholder<string, any>'.
  Overload 2 of 2, '(values: { name: string | SQL<unknown> | Placeholder<string, any>; url: string | SQL<unknown> | Placeholder<string, any>; userId: string | SQL<unknown> | Placeholder<string, any>; id?: number | ... 2 more ... | undefined; createdAt?: SQL<...> | ... 2 more ... | undefined; updatedAt?: SQL<...> | ... 3 more ... | undefined; }[]): PgInsertBase<...>', gave the following error.
    Object literal may only specify known properties, and 'name' does not exist in type '{ name: string | SQL<unknown> | Placeholder<string, any>; url: string | SQL<unknown> | Placeholder<string, any>; userId: string | SQL<unknown> | Placeholder<string, any>; id?: number | ... 2 more ... | undefined; createdAt?: SQL<...> | ... 2 more ... | undefined; updatedAt?: SQL<...> | ... 3 more ... | undefined; }[]'.
Solution
Coercing it with the following removes the problem and in theory should be fine because auth() is called in the middleware and the userId should only be empty if they fail auth correct?

userId: `${metadata.userId}`,
Was this page helpful?