@huntersofbook/auth-vue
TypeScript icon, indicating that this package has built-in type declarations

0.4.1 • Public • Published
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/

    Package Sidebar

    Install

    npm i @huntersofbook/auth-vue

    Weekly Downloads

    13

    Version

    0.4.1

    License

    MIT

    Unpacked Size

    631 kB

    Total Files

    6

    Last publish

    Collaborators

    • productdevbook