0.1.0 • Published 18 days ago

trpc-refresh-token-link v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
18 days ago

TRPC Refresh Token Link

A link for TRPC that refreshes the token when it expires.

Usage

Install the package with your package manager of choice.

npm install trpc-refresh-token-link

Then use it in your code.

import { refreshTokenLink } from "trpc-refresh-token-link";
import { createTRPCClient } from "@trpc/client";

const api = createTRPCClient({
  links: [
    /* other links */
    refreshTokenLink({
      /* options */
    }),
  ],
});

Options

The refreshTokenLink function accepts an object with the following properties:

  • shouldRefresh: (op: Operation) => boolean: A function that determines whether the token should be refreshed for a given operation. To call the refresh token function, return true.
  • refreshToken: (op: Operation) => Promise<void>: A function that refreshes the token and saves it to the client.