@basictech/react 0.7.0-beta.5 → 0.7.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +6 -0
- package/package.json +1 -1
- package/src/AuthContext.tsx +14 -1
package/changelog.md
CHANGED
package/package.json
CHANGED
package/src/AuthContext.tsx
CHANGED
|
@@ -413,8 +413,14 @@ export function BasicProvider({
|
|
|
413
413
|
|
|
414
414
|
if (isExpired) {
|
|
415
415
|
log('token is expired - refreshing ...')
|
|
416
|
+
const refreshToken = token?.refresh_token
|
|
417
|
+
if (!refreshToken) {
|
|
418
|
+
log('Error: No refresh token available for expired token')
|
|
419
|
+
setIsAuthReady(true)
|
|
420
|
+
return
|
|
421
|
+
}
|
|
416
422
|
try {
|
|
417
|
-
const newToken = await fetchToken(
|
|
423
|
+
const newToken = await fetchToken(refreshToken, true)
|
|
418
424
|
fetchUser(newToken?.access_token || '')
|
|
419
425
|
} catch (error) {
|
|
420
426
|
log('Failed to refresh token in checkToken:', error)
|
|
@@ -670,6 +676,13 @@ export function BasicProvider({
|
|
|
670
676
|
}
|
|
671
677
|
|
|
672
678
|
const fetchToken = async (codeOrRefreshToken: string, isRefreshToken: boolean = false): Promise<Token | null> => {
|
|
679
|
+
// Validate input
|
|
680
|
+
if (!codeOrRefreshToken || codeOrRefreshToken.trim() === '') {
|
|
681
|
+
const errorMsg = isRefreshToken ? 'Refresh token is empty or undefined' : 'Authorization code is empty or undefined'
|
|
682
|
+
log('Error:', errorMsg)
|
|
683
|
+
throw new Error(errorMsg)
|
|
684
|
+
}
|
|
685
|
+
|
|
673
686
|
// If this is a refresh token request and one is already in progress, return that promise
|
|
674
687
|
if (isRefreshToken && refreshPromiseRef.current) {
|
|
675
688
|
log('Reusing in-flight refresh token request')
|