Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ServerApp] Firebase Server App feature branch #8005

Merged
merged 23 commits into from
Mar 23, 2024

Conversation

DellaBitta
Copy link
Contributor

@DellaBitta DellaBitta commented Feb 2, 2024

Discussion

Feature branch for the addition of FirebaseServerApp - a tool to ease the use of working with Firebase in SSR frameworks.

Testing

New CI tests in Auth and App, including unit and integration tests.

API Changes

API proposal approved.

DellaBitta and others added 7 commits January 8, 2024 14:32
Baseline addition of the FirebaseServerApp object.
…IdToken (#7944)

Add support for logging-in users with the FirebaseServerApp's authIdToken.

### Testing

Local project testing client-side created users, passing idTokens to serverApps, and logging in the user. Tested with multiple users and multiple instances of FirebaseServerApps w/ Auth.

CI tests (added integration tests).

### API Changes

N/A
…ck later (#7989)

Removed the appCheck and installations token parameters in FirebaseServerAppSettings as they won't be part of our initial launch. Additionally, update the the doxgen comments to no longer refer to these parameters, and to inform users that the User refreshToken will not work for User objects signed in with the authIdToken.
Mangle the name of the ServerAap based on the hash of the parameters passed in.
In addition, return the same instance of app when the same parameters are used.
Update the `FirebaseServerApp` creation to return the same object if an existing object exists with the same configuration. However, the `deleteOnDeref` field is ignored when detecting duplicate apps, since that object reference could vary across multiple SSR rendering passes.

The hope is that a `FirebaseServerApp` instance awaiting deletion from a the `deleteOnDeref` feature maybe be reused if another SSR pass occurs in rapid succession, there by speeding up the SSR code.
Copy link

changeset-bot bot commented Feb 2, 2024

🦋 Changeset detected

Latest commit: db24403

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@firebase/auth Minor
@firebase/app Minor
firebase Minor
@firebase/auth-compat Patch
@firebase/app-compat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Feb 2, 2024

Changeset File Check ✅

  • No modified packages are missing from the changeset file.
  • No changeset formatting errors detected.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 2, 2024

Size Report 1

Affected Products

  • @firebase/app

    TypeBase (0c51501)Merge (8d24593)Diff
    browser14.7 kB18.0 kB+3.30 kB (+22.4%)
    esm519.3 kB23.6 kB+4.31 kB (+22.4%)
    main20.2 kB24.6 kB+4.45 kB (+22.1%)
    module14.7 kB18.0 kB+3.30 kB (+22.4%)
  • @firebase/auth

    TypeBase (0c51501)Merge (8d24593)Diff
    browser177 kB182 kB+4.80 kB (+2.7%)
    cordova205 kB210 kB+4.54 kB (+2.2%)
    esm5231 kB236 kB+5.39 kB (+2.3%)
    main174 kB179 kB+4.33 kB (+2.5%)
    module177 kB182 kB+4.80 kB (+2.7%)
    react-native194 kB199 kB+4.82 kB (+2.5%)
  • @firebase/auth/cordova

    TypeBase (0c51501)Merge (8d24593)Diff
    browser205 kB210 kB+4.54 kB (+2.2%)
    module205 kB210 kB+4.54 kB (+2.2%)
  • @firebase/auth/internal

    TypeBase (0c51501)Merge (8d24593)Diff
    browser188 kB193 kB+4.80 kB (+2.5%)
    esm5244 kB250 kB+5.39 kB (+2.2%)
    main210 kB215 kB+4.49 kB (+2.1%)
    module188 kB193 kB+4.80 kB (+2.5%)
  • @firebase/auth/web-extension

    TypeBase (0c51501)Merge (8d24593)Diff
    browser133 kB137 kB+3.61 kB (+2.7%)
    main148 kB152 kB+3.78 kB (+2.6%)
    module133 kB137 kB+3.61 kB (+2.7%)
  • bundle

    46 size changes

    TypeBase (0c51501)Merge (8d24593)Diff
    analytics (logEvent)44.1 kB44.4 kB+357 B (+0.8%)
    app-check (CustomProvider)36.9 kB37.3 kB+357 B (+1.0%)
    app-check (ReCaptchaEnterpriseProvider)39.5 kB39.8 kB+357 B (+0.9%)
    app-check (ReCaptchaV3Provider)39.4 kB39.8 kB+357 B (+0.9%)
    auth (Anonymous)73.8 kB76.0 kB+2.15 kB (+2.9%)
    auth (EmailAndPassword)82.1 kB84.3 kB+2.19 kB (+2.7%)
    auth (GoogleFBTwitterGitHubPopup)101 kB103 kB+2.43 kB (+2.4%)
    auth (GooglePopup)98.1 kB100 kB+2.32 kB (+2.4%)
    auth (GoogleRedirect)98.3 kB101 kB+2.28 kB (+2.3%)
    auth (Phone)84.4 kB86.6 kB+2.19 kB (+2.6%)
    database (Append to a list of data)149 kB149 kB+357 B (+0.2%)
    database (Filtering data)147 kB148 kB+357 B (+0.2%)
    database (Listen for child events)164 kB164 kB+357 B (+0.2%)
    database (Listen for value events + Detach listeners)164 kB164 kB+357 B (+0.2%)
    database (Listen for value events)164 kB164 kB+357 B (+0.2%)
    database (Read data once)163 kB164 kB+357 B (+0.2%)
    database (Save data as transactions)166 kB166 kB+357 B (+0.2%)
    database (Sort data)149 kB149 kB+357 B (+0.2%)
    database (Write data)148 kB148 kB+357 B (+0.2%)
    firestore (CSI Auto Indexing Disable and Delete)268 kB268 kB+357 B (+0.1%)
    firestore (CSI Auto Indexing Enable)268 kB268 kB+357 B (+0.1%)
    firestore (Persistence)303 kB303 kB+357 B (+0.1%)
    firestore (Query Cursors)247 kB247 kB+357 B (+0.1%)
    firestore (Query)244 kB245 kB+357 B (+0.1%)
    firestore (Read data once)232 kB233 kB+357 B (+0.2%)
    firestore (Read Write w Persistence)322 kB323 kB+357 B (+0.1%)
    firestore (Realtime updates)235 kB235 kB+357 B (+0.2%)
    firestore (Transaction)211 kB212 kB+357 B (+0.2%)
    firestore (Write data)211 kB212 kB+357 B (+0.2%)
    firestore-lite (Query Cursors)89.4 kB89.8 kB+357 B (+0.4%)
    firestore-lite (Query)85.5 kB85.9 kB+357 B (+0.4%)
    firestore-lite (Read data once)61.7 kB62.1 kB+357 B (+0.6%)
    firestore-lite (Transaction)86.6 kB87.0 kB+357 B (+0.4%)
    firestore-lite (Write data)71.3 kB71.6 kB+357 B (+0.5%)
    functions (call)31.5 kB31.8 kB+357 B (+1.1%)
    messaging (send + receive)46.8 kB47.2 kB+357 B (+0.8%)
    performance (trace)51.3 kB51.6 kB+357 B (+0.7%)
    remote-config (getAndFetch)45.8 kB46.2 kB+357 B (+0.8%)
    storage (getBytes)41.6 kB42.0 kB+357 B (+0.9%)
    storage (getDownloadURL)43.7 kB44.0 kB+357 B (+0.8%)
    storage (getMetadata)43.1 kB43.5 kB+357 B (+0.8%)
    storage (list + listAll)42.5 kB42.9 kB+357 B (+0.8%)
    storage (updateMetadata)43.4 kB43.7 kB+357 B (+0.8%)
    storage (uploadBytes)48.2 kB48.6 kB+357 B (+0.7%)
    storage (uploadBytesResumable)58.2 kB58.5 kB+357 B (+0.6%)
    storage (uploadString)48.4 kB48.8 kB+357 B (+0.7%)

  • firebase

    TypeBase (0c51501)Merge (8d24593)Diff
    firebase-app-compat.js29.2 kB31.4 kB+2.17 kB (+7.4%)
    firebase-app.js94.5 kB102 kB+7.10 kB (+7.5%)
    firebase-auth-compat.js137 kB140 kB+2.88 kB (+2.1%)
    firebase-auth-cordova.js174 kB177 kB+3.31 kB (+1.9%)
    firebase-auth-web-extension.js114 kB117 kB+2.72 kB (+2.4%)
    firebase-auth.js147 kB151 kB+3.57 kB (+2.4%)
    firebase-compat.js781 kB786 kB+4.64 kB (+0.6%)
    firebase-performance-standalone-compat.es2017.js90.4 kB93.3 kB+2.85 kB (+3.2%)
    firebase-performance-standalone-compat.js67.6 kB70.3 kB+2.69 kB (+4.0%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/h9ojogTUqS.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 2, 2024

Size Analysis Report 1

This report is too large (448,338 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/1MiSzdfTPs.html

common/api-review/app.api.md Show resolved Hide resolved
packages/app/src/api.ts Show resolved Hide resolved
packages/app/src/firebaseServerApp.ts Show resolved Hide resolved
packages/auth/src/core/auth/auth_impl.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@renkelvin renkelvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for Auth team. Thanks!

common/api-review/app.api.md Show resolved Hide resolved
packages/auth/src/core/user/token_manager.ts Show resolved Hide resolved
DellaBitta and others added 2 commits February 13, 2024 09:55
Updates FirebaseServerApp implementation in Auth to prevent operations that would change the currently logged in user. The user should be that of the authIdToken provided to FirebaseServerApp only.

Note: some of the method implementations currently reside in browser-only files. I added safe guards to these methods even though FirebaseServerApp is not supported in browser enviornments.  These guards protect us in case the methods are later adapted to other environments and/or migrated to other files that are not browser-only. The changes to the browser implementations produce little overhead, so I thought that safety first was the correct call here.
Copy link
Contributor

@egilmorez egilmorez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some things to look at David, thanks!

.changeset/afraid-fishes-repair.md Outdated Show resolved Hide resolved
packages/app/src/api.ts Outdated Show resolved Hide resolved
packages/app/src/api.ts Outdated Show resolved Hide resolved
packages/app/src/api.ts Outdated Show resolved Hide resolved
packages/app/src/public-types.ts Outdated Show resolved Hide resolved
packages/app/src/public-types.ts Outdated Show resolved Hide resolved
packages/app/src/public-types.ts Outdated Show resolved Hide resolved
packages/app/src/public-types.ts Outdated Show resolved Hide resolved
packages/app/src/public-types.ts Outdated Show resolved Hide resolved
packages/app/src/public-types.ts Outdated Show resolved Hide resolved
docs-devsite/app.md Outdated Show resolved Hide resolved
Copy link
Contributor

@egilmorez egilmorez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more things to look at David, thanks!

.changeset/afraid-fishes-repair.md Outdated Show resolved Hide resolved
packages/app/src/public-types.ts Outdated Show resolved Hide resolved
packages/app/src/public-types.ts Outdated Show resolved Hide resolved
packages/app/src/public-types.ts Outdated Show resolved Hide resolved
packages/app/src/public-types.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@egilmorez egilmorez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Text strings LGTM, thanks!

let auth: Auth;

beforeEach(() => {
auth = getTestInstance();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this default instance ever used or are all the tests run on a getTestInstanceForServerApp() instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the tests use this auth instance to create a new user (through varying means) and then uses that newly created user's idToken to initialize FirebaseServerApp.

packages/auth/test/helpers/integration/helpers.ts Outdated Show resolved Hide resolved
packages/auth/src/core/user/user_impl.ts Outdated Show resolved Hide resolved
@DellaBitta DellaBitta marked this pull request as ready for review March 8, 2024 15:02
Copy link
Member

@jamesdaniels jamesdaniels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small matters I raised in comments, otherwise LGTM :shipit:

jamesdaniels and others added 4 commits March 20, 2024 17:35
It turns out the FirebaseServerApp implementation in #8005 was not blocking auth initialization, so when testing end-to-end we were seeing race conditions with auth state. In this PR I address by awaiting the user fetch and moving the implementation into AuthImpl#initializeCurrentUser for cleanliness.
We're rethinking how authIDTokenVerified should be used. It might reside in its own function.

Remove the method for now.
Add a new serverapp string so that register version to track FirebaseServerApp usage.
@DellaBitta DellaBitta merged commit ed84efe into master Mar 23, 2024
44 checks passed
@DellaBitta DellaBitta deleted the feature-firebaseserverapp branch March 23, 2024 12:11
@google-oss-bot google-oss-bot mentioned this pull request Mar 26, 2024
@firebase firebase locked and limited conversation to collaborators Apr 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants