20 lines
514 B
TypeScript
20 lines
514 B
TypeScript
![]() |
import { type Database } from "better-sqlite3"
|
||
|
import { type OAuthTokenResponse } from "@/bank/sparebank1.ts"
|
||
|
|
||
|
const tokenKey = "sparebank1"
|
||
|
|
||
|
export function insertTokens(
|
||
|
db: Database,
|
||
|
oAuthToken: OAuthTokenResponse,
|
||
|
): void {
|
||
|
db.prepare("INSERT INTO tokens VALUES (?, ?)").run(tokenKey, oAuthToken)
|
||
|
}
|
||
|
|
||
|
export function fetchTokens(db: Database): OAuthTokenResponse | null {
|
||
|
return (
|
||
|
(db
|
||
|
.prepare("SELECT data FROM tokens WHERE key = ?")
|
||
|
.get(tokenKey) as OAuthTokenResponse) ?? null
|
||
|
)
|
||
|
}
|