Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom storage never used #37

Open
wa0x6e opened this issue Apr 13, 2018 · 5 comments
Open

Custom storage never used #37

wa0x6e opened this issue Apr 13, 2018 · 5 comments

Comments

@wa0x6e
Copy link

wa0x6e commented Apr 13, 2018

When setting a custom storage engine vie the config

const config = {
  authUrl,
  storage: myStorageEngine,
  userAttributes: {
    firstName: 'first_name',
    imageUrl: 'image',
  },
  userRegistrationAttributes: {
    firstName: 'first_name',
  },
}

the passed custom storage is never used.

I think this is due to this line

const Storage: DeviceStorage = Boolean(storage.flushGetRequests) ? storage : AsyncLocalStorage

Since flushGetRequests is only present in react native localStorage, the code always fallback to AsyncLocalStorage, which itself default to window.localStorage.

Shouldn't that ternary operator expression reversed ?

@alopes
Copy link

alopes commented Jun 6, 2018

There's something wrong with the npm package.

Set it as

"redux-token-auth": "git+https://github.com/kylecorbelli/redux-token-auth.git",

in your package.json and it will work.

@wa0x6e
Copy link
Author

wa0x6e commented Jun 6, 2018

I don't think that's the issue, the code I quoted is from the master branch

@alopes
Copy link

alopes commented Jun 6, 2018

Can you confirm that /dist/services/auth.js is the same on both versions?

npm https://registry.npmjs.org/redux-token-auth/-/redux-token-auth-0.19.0.tgz

exports.persistAuthHeadersInLocalStorage = function (headers) {
    authHeaderKeys.forEach(function (key) {
        localStorage.setItem(key, headers[key]);
    });
};

repo https://github.com/kylecorbelli/redux-token-auth/blob/master/dist/services/auth.js#L53

exports.persistAuthHeadersInDeviceStorage = function (Storage, headers) {
    authHeaderKeys.forEach(function (key) {
        Storage.setItem(key, headers[key]);
    });
};

@wa0x6e
Copy link
Author

wa0x6e commented Jun 6, 2018

I'm not using npm.

The code is from the master branch here:

const Storage: DeviceStorage = Boolean(storage.flushGetRequests) ? storage : AsyncLocalStorage

@alopes
Copy link

alopes commented Jun 6, 2018

From what I can observe, passing custom storage in the config doesn't work at all with the npm package. That's the issue I'm trying to raise here. Regarding your point with storage.flushGetRequests, I believe you are correct. I had to mock flushGetRequests to get cookies as the storage mechanism. Thanks for pointing that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants