matt
Explore posts from serversTTCTheo's Typesafe Cult
•Created by matt on 5/9/2023 in #questions
TS saying I have no ID when I do?
I'm working on a postgres next auth adapter.
Here's my schema:
Here's where I'm having issue in my adapter:
this is what my import looks like:
the insert works for users, sessions and vts, but not accounts? these are my errors:
ID definitely exists, it even shows it existing in the error. deleting the id row does not help.
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()
})
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
})
},
import { users, accounts, sessions, verificationTokens } from './schema'
import { users, accounts, sessions, verificationTokens } from './schema'
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<...>; }[]'.
8 replies