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
0.4.1 • Public • PublishedVersions
Current Tags
- VersionDownloads (Last 7 Days)
- Tag
- 0.4.18
- latest
Version History
- VersionDownloads (Last 7 Days)
- Published
- 0.4.18
- 0.4.1-beta.00
- 0.4.01
- 0.3.10-beta.140
- 0.3.10-beta.130
- 0.3.10-beta.120
- 0.3.10-beta.110
- 0.3.10-beta.101
- 0.3.10-beta.90
- 0.3.10-beta.80
- 0.3.10-beta.70
- 0.3.10-beta.60
- 0.3.10-beta.50
- 0.3.10-beta.40
- 0.3.10-beta.30
- 0.3.10-beta.20
- 0.3.10-beta.00
- 0.3.90
- 0.3.80
- 0.3.70
- 0.3.60
- 0.3.50
- 0.3.40
- 0.3.30
- 0.3.20
- 0.3.10
- 0.3.00
- 0.2.60
- 0.2.50
- 0.2.40
- 0.2.30
- 0.2.20
- 0.2.10
- 0.2.00
- 0.1.70
- 0.1.60
- 0.1.50
- 0.1.40
- 0.1.30
- 0.1.21
- 0.1.10
- 0.1.00
- 0.0.270
- 0.0.260
- 0.0.250
- 0.0.220
Package Sidebar
Install
npm i @huntersofbook/auth-vue
Repository
Weekly Downloads
11
Version
0.4.1
License
MIT
Unpacked Size
631 kB
Total Files
6