Back to Urql

With Refresh Authentication

examples/with-refresh-auth/README.md

1.8.21.6 KB
Original Source

With Refresh Authentication

<p> <a href="https://stackblitz.com/github/urql-graphql/urql/tree/main/examples/with-refresh-auth"> </a> <a href="https://codesandbox.io/p/sandbox/github/urql-graphql/urql/tree/main/examples/with-refresh-auth"> </a> </p>

This example shows urql in use with @urql/exchange-auth's authExchange to support authentication token and refresh token logic. This largely follows the "Authentication" docs page and uses the trygql.formidable.dev/graphql/web-collections schema.

To run this example install dependencies and run the start script:

sh
yarn install
yarn run start
# or
npm install
npm run start

This example contains:

  • The urql bindings and a React app set up in src/App.jsx
  • Some authentication glue code to store the tokens in src/authStore.js
  • The Client and the authExchange from @urql/exchange-auth set up in src/client.js
  • A basic login form in src/pages/LoginForm.jsx
  • And a basic login guard on src/App.jsx (Note: This isn't using a query in this particular component, since this is just an example)