Skip to content

Configure ApolloProvider to always use fresh tokens #1609

Merged
thedavidprice merged 6 commits intoredwoodjs:mainfrom
dac09:fix/use-fresh-tokens
Jan 7, 2021
Merged

Configure ApolloProvider to always use fresh tokens #1609
thedavidprice merged 6 commits intoredwoodjs:mainfrom
dac09:fix/use-fresh-tokens

Conversation

@dac09
Copy link
Copy Markdown
Contributor

@dac09 dac09 commented Jan 7, 2021

  • AuthContext.authToken to be deparacated

Starts fix for #1576. Implements proposal and discussion in #1608

  • Use fresh token for getCurrentUser
  • Use fresh token for other graphql requests
  • Verify and test this

Verified only with firebase, but individual provider changes will be added later.

@dac09 dac09 requested a review from peterp January 7, 2021 14:00
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 7, 2021

📦 Packages for this PR can be downloaded from
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/create-redwood-app-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-api-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-api-server-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-auth-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-cli-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-core-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-dev-server-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-eslint-config-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-eslint-plugin-redwood-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-forms-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-internal-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-router-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-structure-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-testing-0.21.0-e25c682.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1609/redwoodjs-web-0.21.0-e25c682.tgz

Install this PR by running yarn rw upgrade --pr 1609:0.21.0-e25c682

Comment thread packages/auth/src/AuthProvider.tsx Outdated
@@ -20,12 +23,33 @@ const ApolloProviderWithFetchConfig: React.FunctionComponent<{
config?: Omit<ApolloClientOptions<InMemoryCache>, 'cache'>
}> = ({ config = {}, children }) => {
const { uri, headers } = useFetchConfig()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could remove headers here since this is where the auth-token and type came from previously.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing so would save you an extra re-render.

Copy link
Copy Markdown
Contributor Author

@dac09 dac09 Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I intentionally didn't do that, wanted to remove this if/when FetchContext is removed if it makes sense?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that make sense.

Comment thread packages/auth/src/AuthProvider.tsx Outdated
Comment thread packages/auth/src/AuthProvider.tsx Outdated
@dthyresson
Copy link
Copy Markdown
Contributor

I like that the getFreshToken in the earlier version is now just using the getToken.

LGTM 🚀

@thedavidprice thedavidprice added this to the Next Release milestone Jan 7, 2021
@thedavidprice thedavidprice added the release:breaking This PR is a breaking change label Jan 7, 2021
@thedavidprice thedavidprice merged commit ef14ece into redwoodjs:main Jan 7, 2021
thedavidprice added a commit that referenced this pull request Jan 7, 2021
@thedavidprice thedavidprice removed this from the Next Release milestone Jan 7, 2021
@thedavidprice
Copy link
Copy Markdown
Contributor

REVERTED

See #1611

@dac09 dac09 mentioned this pull request Jan 12, 2021
3 tasks
dac09 added a commit to dac09/redwood that referenced this pull request Jan 12, 2021
…h-tokens

* 'main' of github.com:redwoodjs/redwood:
  Move whatwg-fetch from devDep to dep
  Adds mockCurrentUser() to api-side jest
  v0.22.1
  v0.22.0
  Revert "Configure ApolloProvider to always use fresh tokens  (redwoodjs#1609)" (redwoodjs#1611)
  Configure ApolloProvider to always use fresh tokens  (redwoodjs#1609)
  Ignore *.scenarios.* files. (redwoodjs#1607)
  upgrade prisma v2.12.1 (redwoodjs#1604)
  Test Scenarios (redwoodjs#1465)
  Use relative path to config stories location (redwoodjs#1509)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:breaking This PR is a breaking change topic/auth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to refresh Auth token once RedwoodProvider is mounted. refresh auth tokens when they're invalidated

4 participants