Add a resaturation function for auth User instances
This allows symmetry for the user object:
const user = (await signInAnonymously(auth)).user;
const userString = JSON.stringify(user);
const resaturated = /* new: */ userFromJSON(auth, userString);
This also allows more flexibility in environments whose storage we don't always fully support (see https://github.com/firebase/firebase-js-sdk/issues/1874, https://github.com/firebase/firebase-js-sdk/discussions/4468)
Pending API review.
⚠️ No Changeset found
Latest commit: 5ac8e3b7d5ce055daa53005de635baaaecc35b54
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Binary Size Report
Affected SDKs
No changes between base commit (c6eadf7f) and head commit (4f547b92).
Test Logs
Base (c6eadf7f): https://github.com/firebase/firebase-js-sdk/actions/runs/576053606Head (4f547b92): https://github.com/firebase/firebase-js-sdk/actions/runs/576054842
Size Analysis Report
Affected Products
@firebase/auth-expuserFromJSONSize Table
Type Base (c6eadf7f) Head (4f547b92) Diff size?28.0 kB? (?)size-with-ext-deps?38.7 kB? (?)Dependency Table
Type Base (c6eadf7f) Head (4f547b92) Diff functions?47 dependencies
_assert _castAuth _createError _emulatorUrl _fail _getBrowserName _getClientVersion _getCurrentScheme _getFinalTarget _getInstance _getUserLanguage _isAndroid _isBlackBerry _isChromeIOS _isFirefox _isHttpOrHttps _isIEMobile _isOnline _isSafari _isWebOS _logError _logoutIfInvalidated _parseToken _performApiRequest _performFetchWithErrorHandling _persistenceKeyName _prodErrorMap _reloadWithoutSaving _tokenExpiresIn assertStringOrUndefined createErrorInternal debugAssert debugFail deleteAccount extractProviderData getAccountInfo getIdTokenResult getVersionForPlatform isUserInvalidated makeTaggedError mergeProviderData registerAuth reload requestStsToken secondsStringToMilliseconds userFromJSON utcTimestampToDateString
?classes?12 dependencies
AuthImpl AuthInternal Delay FetchProvider InMemoryPersistence NetworkTimeout PersistenceUserManager ProactiveRefresh StsTokenManager Subscription UserImpl UserMetadata
?variables?11 dependencies
DEFAULT_API_TIMEOUT_MS NETWORK_TIMEOUT NETWORK_TIMEOUT_DELAY PING_TIMEOUT SERVER_ERROR_MAP _DEFAULT_AUTH_ERROR_FACTORY _POLL_WINDOW_CLOSE_TIMEOUT inMemoryPersistence instanceCache logClient version
?enums??External Dependency Table
Module Base (c6eadf7f) Head (4f547b92) Diff @firebase/app-exp?SDK_VERSION _registerComponent registerVersion
?@firebase/util?ErrorFactory FirebaseError base64Decode createSubscribe getUA isBrowserExtension isMobileCordova isReactNative querystring
?@firebase/logger?LogLevel Logger
?tslib?__rest
?@firebase/component?Component
?
Test Logs
- Base (c6eadf7f): https://github.com/firebase/firebase-js-sdk/actions/runs/576053606
- Head (4f547b92): https://github.com/firebase/firebase-js-sdk/actions/runs/576054842
This is exactly what I need. Any workarounds I can use until this is merged?
Any movement on this PR? I would really like to keep my client-side node apps running in stateless containers authenticated with a first-party solution
@sam-gc A feature like this would be extremely useful for MV3 Chrome Extensions, where the background service worker has a short lifespan. In MV3, authentication is crippled, see #5588
If the authentication could be handled on a normal website, and the user data passed to the extension via external messaging, then the extension could authenticate using updateCurrentUser and save the user in extension storage. Then when the service worker restarts, the extension would update the user from storage.
This way, the authentication use case is greatly simplified, and the Chrome extension code is not concerned with authentication itself.
Was this function 'userFromJSON' ever released? I can't seem to find it in any documentation. As mentioned above, Chrome Extension firebase google authentication is very hard to achieve in the main extension context. The only viable option is to do the authentication offscreen and then use 'updateCurrentUser' to populate the Auth of the main context. But that requires creating a new user from the stingified creds passed to the main context via messaging.