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

wip(auth): Get fresh token before making request #1577

Closed
wants to merge 2 commits into from

Conversation

dac09
Copy link
Contributor

@dac09 dac09 commented Dec 11, 2020

Starts fix for #1576

  • Use fresh token for getCurrentUser
  • Use fresh token for other graphql requests
  • Add a way to watch for token changes from client
  • Verify and test this

@github-actions
Copy link

github-actions bot commented Dec 11, 2020

@peterp
Copy link
Contributor

peterp commented Dec 16, 2020

I'm a bit cautious of this approach, since it changes a bunch of assumptions and I'm not fully grokking the consequences of that.

Backing up a bit. I think the root cause for this problem is that we're not dynamically requesting the auth token on each request.

This is solvable in Apollo by using an http auth-link (pseudo-code):

import { AuthContext } from '@redwoodjs/auth'

const authLink = setContext((_, { headers }) => {
  // get the authentication token
  const { token } = AuthContext._currentValue

  // return the headers to the context so httpLink can read them
  return {
    headers: {
      ...headers,
      authorization: token ? `Bearer ${token}` : "",
    }
  }
});

@viperfx
Copy link
Contributor

viperfx commented Dec 22, 2020

My redwood app is still pre-production, but I face this almost on a daily basis during development. Token expires and all subsequent navigation inside redwood gives a 500 status from the API. (I am using Firebase as well).

Would the above suggestion with auth-link be implemented on global level in redwood or on an auth provider level?

@peterp
Copy link
Contributor

peterp commented Jan 7, 2021

@viperfx We'll solve this for everyone.

@dac09
Copy link
Contributor Author

dac09 commented Jan 7, 2021

Closing this, new solution on the way.

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