Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Auth token keep expiring #202

Closed
ylac opened this issue Jul 3, 2017 · 7 comments
Closed

Auth token keep expiring #202

ylac opened this issue Jul 3, 2017 · 7 comments

Comments

@ylac
Copy link

ylac commented Jul 3, 2017

Hi, I'm having a recurrent issue where my auth token keep expiring on app startup after some time. I'm using the hybrid HTTP/WS setup where my configuration looks like:

const wsClient = new SubscriptionClient(`wss://${scapholdURL}`, {
 reconnect: true,
 timeout: 15000
});

const networkInterface = createNetworkInterface({
 uri: `https://${scapholdURL}`
});

const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
  networkInterface,
  wsClient
);

networkInterfaceWithSubscriptions.use([{
  applyMiddleware (req, next) {
   if (!req.options.headers) {
     req.options.headers = {};
   }
   // get the authentication token from store if it exists
   var { auth0IdToken } = store.getState().login;
   if (auth0IdToken) {
     req.options.headers.authorization = `Bearer ${auth0IdToken}`;
    // req.options.headers.authorization = "1";
     console.log(`Using header auth from store.getState: ${req.options.headers.authorization}`);
     next();
   } else if (auth0IdToken === undefined) {
     getStoredState({storage: AsyncStorage}, (err, restoredState) => {
       console.log(`Get auth0Idtoken from AsyncStorage`);
       if (err) {
         console.log(`Get auth0IdToken from stored state error ${err}`);
       } else {
         var { auth0IdToken } = restoredState.login;
         console.log(`auth0IdToken ${auth0IdToken}`);
         if (auth0IdToken) {
           req.options.headers.authorization = `Bearer ${auth0IdToken}`;
         } else {
           console.log(`No valid auth0IdToken: ${auth0IdToken}`);
         }
       }
       next();
     });
   } else {
     console.log(`No valid auth0IdToken: ${auth0IdToken}`);
     next();
   }
 }
}]);

I have some subscriptions that initialise on app start. Do I need to pass the auth token via the context on subscribe as per #33/ #75, and if so, what's the syntax for that?

@mistic
Copy link
Contributor

mistic commented Jul 3, 2017

@ylac Do u think your problem cloud be related with #197 ?

@ylac
Copy link
Author

ylac commented Jul 3, 2017

@mistic Possibly, my issue mainly occurs after being logged in for maybe an hour or so and then opening the app again.

@mistic
Copy link
Contributor

mistic commented Jul 3, 2017

@ylac yeah should be this error :) lets wait for the release and please inform here as soon as u test it :)

@ylac
Copy link
Author

ylac commented Jul 5, 2017

@mistic Okay great, looking forward to testing it :).

@mistic
Copy link
Contributor

mistic commented Jul 7, 2017

@ylac could u please test the version in the master branch? It should be possible right now using this in your package.json:

"subscriptions-transport-ws": "apollographql/subscriptions-transport-ws#master"

Please let me know if your issue is solved :)

@ylac
Copy link
Author

ylac commented Jul 8, 2017

@mistic Unfortunately the issue is still occurring with the new version. I think I may need to pass the auth token as context when making a subscribe request?

@ylac
Copy link
Author

ylac commented Jul 26, 2017

Okay I think this isn't an issue with subscriptions because it happens when doing plain queries as well.

@ylac ylac closed this as completed Jul 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants