import { getUserManager } from './userManager' ; import { tinyMemoize } from './utils/tinyMemoize' ; export const MIN_EXPIRY_FOR_RE_SIGNIN = 10 ; export const MIN_EXPIRY_FOR_PRE_SIGNIN = 120 ; const fetchNewToken = tinyMemoize ( ( ) => { return getUserManager ( ) . signinSilent ( ) . catch ( ( ) => null ) ; } ) ; export const getAccessToken = async ( ) => { let user = await getUserManager ( ) . getUser ( ) ; if ( ! user ) { return null ; } if ( user . expires_in < MIN_EXPIRY_FOR_RE_SIGNIN ) { user = await fetchNewToken ( ) ; if ( ! user ) { return null ; } } else if ( user . expires_in < MIN_EXPIRY_FOR_PRE_SIGNIN ) { fetchNewToken ( ) ; } return user . access_token ; } ;