Skip to content

Commit 3f8fc13

Browse files
committed
fix: fetch fresh user if not found in the user storage
1 parent 159c991 commit 3f8fc13

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/GoTrueClient.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,17 +2013,34 @@ export default class GoTrueClient {
20132013
}
20142014
}
20152015
}
2016+
} else if (
2017+
currentSession.user &&
2018+
(currentSession.user as any).__isUserNotAvailableProxy === true
2019+
) {
2020+
// If we have a proxy user, try to get the real user data
2021+
try {
2022+
const { data, error: userError } = await this._getUser(currentSession.access_token)
2023+
2024+
if (!userError && data?.user) {
2025+
currentSession.user = data.user
2026+
await this._saveSession(currentSession)
2027+
await this._notifyAllSubscribers('SIGNED_IN', currentSession)
2028+
} else {
2029+
this._debug(debugName, 'could not get user data, skipping SIGNED_IN notification')
2030+
}
2031+
} catch (getUserError) {
2032+
console.error('Error getting user data:', getUserError)
2033+
this._debug(
2034+
debugName,
2035+
'error getting user data, skipping SIGNED_IN notification',
2036+
getUserError
2037+
)
2038+
}
20162039
} else {
20172040
// no need to persist currentSession again, as we just loaded it from
20182041
// local storage; persisting it again may overwrite a value saved by
20192042
// another client with access to the same local storage
2020-
2021-
// Prevent sending a proxy user object as it can't be structured cloned
2022-
let finalPayloadSession =
2023-
currentSession.user && (currentSession.user as any).__isUserNotAvailableProxy
2024-
? null
2025-
: currentSession
2026-
await this._notifyAllSubscribers('SIGNED_IN', finalPayloadSession)
2043+
await this._notifyAllSubscribers('SIGNED_IN', currentSession)
20272044
}
20282045
} catch (err) {
20292046
this._debug(debugName, 'error', err)

0 commit comments

Comments
 (0)