lets try storing as tmp file again

This commit is contained in:
spencerwooo
2021-12-31 16:56:18 +08:00
parent 71ba7ff67c
commit 2e6c652ea1
3 changed files with 85 additions and 67 deletions
+19 -35
View File
@@ -1,45 +1,29 @@
// This should be only used on the server side, where the tokens are stored with KV store using
// a file system based storage. The tokens are stored in the file system as JSON at /tmp path.
import os from 'os'
import Keyv from 'keyv'
import { KeyvFile } from 'keyv-file'
// console.log(`${os.tmpdir()}/od-auth-token.json`)
export async function getOdAuthTokens(keyv: Keyv): Promise<{ accessToken: unknown; refreshToken: unknown }> {
const accessToken = await keyv.get('access_token')
const refreshToken = await keyv.get('refresh_token')
export default class TokenStore {
kv: Keyv
constructor() {
this.kv = new Keyv()
// this.kv = new Keyv({
// store: new KeyvFile({
// filename: `${os.tmpdir()}/od-auth-token.json`,
// }),
// })
console.log('TokenStore constructor')
}
async getOdAuthTokens(): Promise<{ accessToken: unknown; refreshToken: unknown }> {
const accessToken = await this.kv.get('access_token')
const refreshToken = await this.kv.get('refresh_token')
return {
accessToken,
refreshToken,
}
}
async storeOdAuthTokens({
return {
accessToken,
accessTokenExpiry,
refreshToken,
}: {
accessToken: string
accessTokenExpiry: number
refreshToken: string
}): Promise<void> {
await this.kv.set('access_token', accessToken, accessTokenExpiry)
await this.kv.set('refresh_token', refreshToken)
}
}
export async function storeOdAuthTokens({
accessToken,
accessTokenExpiry,
refreshToken,
keyv,
}: {
accessToken: string
accessTokenExpiry: number
refreshToken: string
keyv: Keyv
}): Promise<void> {
await keyv.set('access_token', accessToken, accessTokenExpiry)
await keyv.set('refresh_token', refreshToken)
}