TS saying I have no ID when I do?

I'm working on a postgres next auth adapter. Here's my schema:
export const accounts = pgTable('accounts', {
id: text('id').notNull(),
userId: text('userId').notNull(),
type: text('type').$type<ProviderType>().notNull(),
provider: text('provider').notNull(),
providerAccountId: text('providerAccountId').notNull(),
access_token: text('access_token'),
expires_at: integer('expires_at'),
id_token: text('id_token'),
refresh_token: text('refresh_token'),
refresh_token_expires_in: integer('refresh_token_expires_in'),
scope: text('scope'),
token_type: text('token_type'),
created_at: timestamp('created_at').defaultNow().notNull(),
updated_at: timestamp('updated_at').defaultNow().notNull()
})
export const accounts = pgTable('accounts', {
id: text('id').notNull(),
userId: text('userId').notNull(),
type: text('type').$type<ProviderType>().notNull(),
provider: text('provider').notNull(),
providerAccountId: text('providerAccountId').notNull(),
access_token: text('access_token'),
expires_at: integer('expires_at'),
id_token: text('id_token'),
refresh_token: text('refresh_token'),
refresh_token_expires_in: integer('refresh_token_expires_in'),
scope: text('scope'),
token_type: text('token_type'),
created_at: timestamp('created_at').defaultNow().notNull(),
updated_at: timestamp('updated_at').defaultNow().notNull()
})
Here's where I'm having issue in my adapter:
async linkAccount(account) {
await db.insert(accounts).values({
id: 'c' + uuid(),
userId: account.userId,
// type: account.type,
provider: account.provider as string,
providerAccountId: account.providerAccountId as string,
refreshToken: account.refreshToken,
refresh_token_expires_in: account.refresh_token_expires_in,
accessToken: account.accessToken,
expires_at: account.expires_at as number,
token_type: account.token_type,
scope: account.scope,
id_token: account.id_token,
created_at: account.created_at,
updated_at: account.updated_at
})
},
async linkAccount(account) {
await db.insert(accounts).values({
id: 'c' + uuid(),
userId: account.userId,
// type: account.type,
provider: account.provider as string,
providerAccountId: account.providerAccountId as string,
refreshToken: account.refreshToken,
refresh_token_expires_in: account.refresh_token_expires_in,
accessToken: account.accessToken,
expires_at: account.expires_at as number,
token_type: account.token_type,
scope: account.scope,
id_token: account.id_token,
created_at: account.created_at,
updated_at: account.updated_at
})
},
this is what my import looks like:
import { users, accounts, sessions, verificationTokens } from './schema'
import { users, accounts, sessions, verificationTokens } from './schema'
the insert works for users, sessions and vts, but not accounts? these are my errors:
Argument of type '{ id: string; userId: string; provider: string; providerAccountId: string; refreshToken: unknown; refresh_token_expires_in: unknown; accessToken: unknown; expires_at: number; token_type: string; scope: string; id_token: string; created_at: unknown; updated_at: unknown; }' is not assignable to parameter of type '{ id: string | SQL<unknown> | Placeholder<string, any>; provider: string | SQL<unknown> | Placeholder<string, any>; providerAccountId: string | SQL<unknown> | Placeholder<...>; ... 10 more ...; updated_at?: SQL<...> | ... 1 more ... | Placeholder<...>; }[]'.
Argument of type '{ id: string; userId: string; provider: string; providerAccountId: string; refreshToken: unknown; refresh_token_expires_in: unknown; accessToken: unknown; expires_at: number; token_type: string; scope: string; id_token: string; created_at: unknown; updated_at: unknown; }' is not assignable to parameter of type '{ id: string | SQL<unknown> | Placeholder<string, any>; provider: string | SQL<unknown> | Placeholder<string, any>; providerAccountId: string | SQL<unknown> | Placeholder<...>; ... 10 more ...; updated_at?: SQL<...> | ... 1 more ... | Placeholder<...>; }[]'.
Object literal may only specify known properties, and 'id' does not exist in type '{ id: string | SQL<unknown> | Placeholder<string, any>; provider: string | SQL<unknown> | Placeholder<string, any>; providerAccountId: string | SQL<unknown> | Placeholder<...>; ... 10 more ...; updated_at?: SQL<...> | ... 1 more ... | Placeholder<...>; }[]'.
Object literal may only specify known properties, and 'id' does not exist in type '{ id: string | SQL<unknown> | Placeholder<string, any>; provider: string | SQL<unknown> | Placeholder<string, any>; providerAccountId: string | SQL<unknown> | Placeholder<...>; ... 10 more ...; updated_at?: SQL<...> | ... 1 more ... | Placeholder<...>; }[]'.
ID definitely exists, it even shows it existing in the error. deleting the id row does not help.
4 Replies
Andrii Sherman
Can you share account type? linkAccount function param Trying to debug it
matt
matt2y ago
it was a very small silly error on my part, it should be expires_in instead of expires_at
Andrii Sherman
Got it
matt
matt2y ago
appreciate you looking to debug 🙏 it's frustrating typescript gave me the error on the id, when the error was the expires_at
Want results from more Discord servers?
Add your server