import { Preferences } from '@capacitor/preferences'
import { AuthOptions, AuthStorageAsync } from '../types/index'
export class CapacitorStorage implements AuthStorageAsync {
async set(key: string, value: any) {
await Preferences.set({ key, value: JSON.stringify(value) })
}
async get(key: string, defaultValue: any) {
try {
const { value } = await Preferences.get({ key })
return JSON.parse(value!)
}
catch {
return defaultValue
}
}
async remove(key: string) {
await Preferences.remove({ key })
}
async clear(options: AuthOptions) {
await Preferences.remove({ key: options.token.storageName })
await Preferences.remove({ key: options.user.storageName })
await Preferences.remove({ key: options.expiredStorage })
await Preferences.remove({ key: options.refreshToken.storageName })
}
}
@huntersofbook/auth-vue![This package contains built-in TypeScript declarations TypeScript icon, indicating that this package has built-in type declarations](https://static-production.npmjs.com/255a118f56f5346b97e56325a1217a16.svg)
0.4.1 • Public • Published Readme
Keywords
nonePackage Sidebar
Install
npm i @huntersofbook/auth-vue
Repository
Weekly Downloads
13
Version
0.4.1
License
MIT
Unpacked Size
631 kB
Total Files
6