Skip to content

Commit

Permalink
Merge pull request #12 from mvanroon/feature/expose-refresh-state
Browse files Browse the repository at this point in the history
feat: expose refresh state
  • Loading branch information
mvanroon committed Oct 22, 2021
2 parents 3e2eac4 + 593c47f commit 636adb2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jwtDecode from 'jwt-decode'
import jwtDecode, { JwtPayload } from 'jwt-decode'

import { AxiosInstance, AxiosRequestConfig } from 'axios'
import AsyncStorage from '@react-native-async-storage/async-storage'
Expand Down Expand Up @@ -151,7 +151,7 @@ const isTokenExpired = (token: Token): boolean => {
* @returns {string} Unix timestamp
*/
const getTimestampFromToken = (token: Token): number | undefined => {
const decoded = jwtDecode(token) as { [key: string]: number }
const decoded = jwtDecode<JwtPayload>(token)

return decoded.exp
}
Expand Down Expand Up @@ -270,6 +270,24 @@ type RequestsQueue = {
let isRefreshing = false
let queue: RequestsQueue = []

/**
* Check if tokens are currently being refreshed
*
* @returns {boolean} True if the tokens are currently being refreshed, false is not
*/
export function getIsRefreshing(): boolean {
return isRefreshing
}

/**
* Update refresh state
*
* @param {boolean} newRefreshingState
*/
export function setIsRefreshing(newRefreshingState: boolean): void {
isRefreshing = newRefreshingState
}

/**
* Function that resolves all items in the queue with the provided token
* @param token New access token
Expand Down

0 comments on commit 636adb2

Please sign in to comment.