Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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