feathersjs-ecosystem / authentication-client

[MOVED] The authentication client
https://github.com/feathersjs/feathers
MIT License
41 stars 19 forks source link

auth.config storage with localForage #107

Closed oscarlomas09 closed 5 years ago

oscarlomas09 commented 6 years ago

Steps to reproduce

(First please check that this issue is not already solved as described here)

Trying to configure feathers-client with authentication storage fails. The docs suggest using appropriate storage items for localStorage and one of those suggestions is using localForage. However, the localForage is asynchronous and the Storage object for it returns promises. Is there any example on interfacing localForage with the authentication-client

Expected behavior

import feathers from '@feathersjs/feathers'
import socketio from '@feathersjs/socketio-client'
import auth from '@feathersjs/authentication-client'
import io from 'socket.io-client'
import localForage from "localforage";

const feathersClient = feathers()
  .configure(socketio(socket))
  .configure(auth({ storage: localForage })) // should work?

and the localForage interface

interface LocalForageDbMethodsCore {
    getItem<T>(key: string, callback?: (err: any, value: T) => void): Promise<T>;

    setItem<T>(key: string, value: T, callback?: (err: any, value: T) => void): Promise<T>;

    removeItem(key: string, callback?: (err: any) => void): Promise<void>;

    clear(callback?: (err: any) => void): Promise<void>;

    length(callback?: (err: any, numberOfKeys: number) => void): Promise<number>;

    key(keyIndex: number, callback?: (err: any, key: string) => void): Promise<string>;

    keys(callback?: (err: any, keys: string[]) => void): Promise<string[]>;

    iterate<T, U>(iteratee: (value: T, key: string, iterationNumber: number) => U,
            callback?: (err: any, result: U) => void): Promise<U>;
}

Actual behavior

Argument of type '{ storage: LocalForage; }' is not assignable to parameter of type 'FeathersAuthClientConfig'.
  Types of property 'storage' are incompatible.
    Type 'LocalForage' is not assignable to type 'Storage'.
      Types of property 'length' are incompatible.
        Type '(callback?: ((err: any, numberOfKeys: number) => void) | undefined) => Promise<number>' is not assignable to type 'number'.
     9 | const feathersClient = feathers()
    10 |   .configure(socketio(socket))
  > 11 |   .configure(auth({ storage: localForage }))

System configuration

Typescript 3.0.1 Windows 10 - 64 bit

Module versions (especially the part that's not working):

"dependencies": {
    "@feathersjs/authentication-client": "^1.0.2",
    "@feathersjs/feathers": "^3.1.7",
    "@feathersjs/socketio-client": "^1.1.0",
    "@types/feathersjs__authentication-client": "^1.0.4",
    "@types/feathersjs__feathers": "^3.0.4",
    "@types/feathersjs__socketio-client": "^1.0.1",
    "@types/socket.io-client": "^1.4.32",
    "axios": "^0.18.0",
    "feathers-vuex": "^1.4.8",
    "localforage": "^1.7.2",
    "register-service-worker": "^1.0.0",
    "socket.io-client": "^2.1.1",
    "vue": "^2.5.17",
    "vue-class-component": "^6.0.0",
    "vue-property-decorator": "^7.0.0",
    "vue-router": "^3.0.1",
    "vuelidate": "^0.7.4",
    "vuex": "^3.0.1"
  },

NodeJS version: npm -v > 5.6.0

daffl commented 6 years ago

Ignore the typings. It will work with an asynchronous storage.

daffl commented 5 years ago

All typings have been fixed in Feathers v4 authentication. Please see the migration guide for more information. Closing this issue in order to archive this repository. Related issues can be opened at the new code location in the Feathers main repository.