tn-apollo-link-token-refresh
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

Apollo Refresh Link

export const apolloLinkRefresh = new ApolloLinkTokenRefresh({
  safety: 60,
  getAccessToken: () => login.accessToken.get(),
  beforeRefresh: () => null,
  refresh: ({ onSuccess, onError, onFinally }) => {
    login.refresh({
      onError,
      onFinally,
      onSuccess: () => {
        login.setAccessToken(accessToken)
        login.setRefreshToken(refreshToken)
        onSuccess && onSuccess()
      },
    })
  },
})

Creating Apollo Link

const apolloLinks = ApolloLink.from([
  apolloLinkRefresh, 
  apolloLinkRequest,
  apolloLinkHTTP
]) 

ApolloLinkTokenRefreshOptions

Property Type Note
safety seconds number A safety time so that AccessToken does not expire on the fly
getAccessToken () => string A method returning current AccessToken
beforeRefresh () => void This method will be called before refreshing AccessToken
refresh (RefreshProps) => void refresh() method and it's handlers
interface RefreshProps {
  onSuccess: () => void
  onError: () => void
  onFinally: () => void
}

Readme

Keywords

none

Package Sidebar

Install

npm i tn-apollo-link-token-refresh

Weekly Downloads

2

Version

2.0.1

License

MIT

Unpacked Size

17.7 kB

Total Files

30

Last publish

Collaborators

  • turnova