obabichev / react-token-auth

84 stars 22 forks source link

Add getToken to createAuthProvider response #12

Closed qooplmao closed 4 years ago

qooplmao commented 4 years ago

I'm planning on using this with the Apollo GraphQL client rather than the provided authFetch so I need a way to get the token and I don't like the idea of going to the localStorage directly as it kind of defeats the purpose of using this package. Long story short (and as the title says), I've add a getToken function to the response from createAuthProvider.

My thinking is that this would be used like...

import {createAuthProvider} from 'react-token-auth';

const [useAuth, authFetch, login, logout, getToken] = createAuthProvider(...);

export {
  useAuth,
  login,
  logout,
  getToken
}
import { getToken } from '@/authProvider';

// const token = await getToken();

Is that correct? If not then this PR will make no sense.

qooplmao commented 4 years ago

Ignore this. I just discovered, with a very small amount of effort, that I can use a custom fetch with the Apollo client so the authFetch will actually fit my requirements making this PR somewhat useless.