(
input: Pick<Account, 'provider' | 'providerAccountId'> & {
// eslint-disable-next-line @typescript-eslint/naming-convention
access_token?: string;
// eslint-disable-next-line @typescript-eslint/naming-convention
refresh_token?: string;
scope?: string;
// eslint-disable-next-line @typescript-eslint/naming-convention
expires_at?: number;
// eslint-disable-next-line @typescript-eslint/naming-convention
token_type?: string;
// eslint-disable-next-line @typescript-eslint/naming-convention
session_state?: string;
type?: string;
// eslint-disable-next-line @typescript-eslint/naming-convention
id_token?: string;
},
)
| 14 | } from './schema'; |
| 15 | |
| 16 | export async function updateProviderAuthToken( |
| 17 | input: Pick<Account, 'provider' | 'providerAccountId'> & { |
| 18 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 19 | access_token?: string; |
| 20 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 21 | refresh_token?: string; |
| 22 | scope?: string; |
| 23 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 24 | expires_at?: number; |
| 25 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 26 | token_type?: string; |
| 27 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 28 | session_state?: string; |
| 29 | type?: string; |
| 30 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 31 | id_token?: string; |
| 32 | }, |
| 33 | ) { |
| 34 | const { provider, providerAccountId, ...update } = input; |
| 35 | |
| 36 | const zAccountUpdate = z.object({ |
| 37 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 38 | access_token: z.string().optional(), |
| 39 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 40 | refresh_token: z.string().optional(), |
| 41 | scope: z.string().optional(), |
| 42 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 43 | expires_at: z.number().optional(), |
| 44 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 45 | token_type: z.string().optional(), |
| 46 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 47 | session_state: z.string().optional(), |
| 48 | type: z.enum(['oidc', 'oauth', 'email']).optional(), |
| 49 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 50 | id_token: z.string().optional(), |
| 51 | }); |
| 52 | |
| 53 | await db |
| 54 | .update(dbAccounts) |
| 55 | .set(zAccountUpdate.parse(update)) |
| 56 | .where( |
| 57 | and( |
| 58 | eq(dbAccounts.provider, provider), |
| 59 | eq(dbAccounts.providerAccountId, providerAccountId), |
| 60 | ), |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | // todo: move to its own package |
| 65 | //! MAINLY TEST ONLY |
no test coverage detected