- 
                Notifications
    You must be signed in to change notification settings 
- Fork 984
Auth cookie persistence #8839
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
          
     Merged
      
      
    
  
     Merged
                    Auth cookie persistence #8839
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            26 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      d3792b5
              
                First.
              
              
                jamesdaniels 00b0059
              
                Merge branch 'main' into jamesdaniels_authCookiePersistence
              
              
                jamesdaniels aba574a
              
                First.
              
              
                jamesdaniels 8acd061
              
                Sentinal as ""
              
              
                jamesdaniels a727dce
              
                Cleanup and add cookieStore fallback
              
              
                jamesdaniels 769624f
              
                Cleanup unsubscribes
              
              
                jamesdaniels 31cb8b0
              
                Cleanup and add docs
              
              
                jamesdaniels 0bef1eb
              
                Cleanup and add docs
              
              
                jamesdaniels efdafc5
              
                Changeset
              
              
                jamesdaniels da747d7
              
                Beta tag
              
              
                jamesdaniels 27c203a
              
                Merge branch 'main' into jamesdaniels_authCookiePersistence
              
              
                jamesdaniels 7f850fc
              
                Remove unneeded changes
              
              
                jamesdaniels f587178
              
                Address feedback, cleanup endpoint check
              
              
                jamesdaniels 5568a01
              
                Formatting
              
              
                jamesdaniels 0ac4cad
              
                Cleanup
              
              
                jamesdaniels d278dcf
              
                Tweak wording for doc
              
              
                jamesdaniels fc1ce03
              
                Code format COOKIE
              
              
                jamesdaniels 6acbb6a
              
                Formatting
              
              
                jamesdaniels 8f97100
              
                Cleanup
              
              
                jamesdaniels 3291f23
              
                Formatting
              
              
                jamesdaniels 0fb3804
              
                Update docs
              
              
                jamesdaniels bdeeead
              
                Fix test
              
              
                jamesdaniels 5a913c9
              
                Comments!
              
              
                jamesdaniels d3fa466
              
                Fix for the auth race condition
              
              
                jamesdaniels 680583e
              
                Address erics feedback
              
              
                jamesdaniels 1e50af6
              
                Forgot to commit the actual source file
              
              
                jamesdaniels File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| 'firebase': minor | ||
| '@firebase/auth': minor | ||
| --- | ||
|  | ||
| Adding `Persistence.COOKIE` a new persistence method backed by cookies. The | ||
| `browserCookiePersistence` implementation is designed to be used in conjunction with middleware that | ||
| ensures both your front and backend authentication state remains synchronized. | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -120,6 +120,10 @@ export class AuthImpl implements AuthInternal, _FirebaseService { | |
| _tenantRecaptchaConfigs: Record<string, RecaptchaConfig> = {}; | ||
| _projectPasswordPolicy: PasswordPolicyInternal | null = null; | ||
| _tenantPasswordPolicies: Record<string, PasswordPolicyInternal> = {}; | ||
| _resolvePersistenceManagerAvailable: | ||
| | ((value: void | PromiseLike<void>) => void) | ||
| | undefined = undefined; | ||
| _persistenceManagerAvailable: Promise<void>; | ||
| readonly name: string; | ||
|  | ||
| // Tracks the last notified UID for state change listeners to prevent | ||
|  | @@ -139,6 +143,11 @@ export class AuthImpl implements AuthInternal, _FirebaseService { | |
| ) { | ||
| this.name = app.name; | ||
| this.clientVersion = config.sdkClientVersion; | ||
| // TODO(jamesdaniels) explore less hacky way to do this, cookie authentication needs | ||
| // persistenceMananger to be available. see _getFinalTarget for more context | ||
| this._persistenceManagerAvailable = new Promise<void>( | ||
| resolve => (this._resolvePersistenceManagerAvailable = resolve) | ||
| ); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can i haz  | ||
| } | ||
|  | ||
| _initializeWithPersistence( | ||
|  | @@ -160,6 +169,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService { | |
| this, | ||
| persistenceHierarchy | ||
| ); | ||
| this._resolvePersistenceManagerAvailable?.(); | ||
|  | ||
| if (this._deleted) { | ||
| return; | ||
|  | @@ -524,10 +534,14 @@ export class AuthImpl implements AuthInternal, _FirebaseService { | |
| } | ||
| } | ||
|  | ||
| _getPersistence(): string { | ||
| _getPersistenceType(): string { | ||
| return this.assertedPersistence.persistence.type; | ||
| } | ||
|  | ||
| _getPersistence(): PersistenceInternal { | ||
| return this.assertedPersistence.persistence; | ||
| } | ||
|  | ||
| _updateErrorMap(errorMap: AuthErrorMap): void { | ||
| this._errorFactory = new ErrorFactory<AuthErrorCode, AuthErrorParams>( | ||
| 'auth', | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI using this dev-dep for types, somewhere else I tried this ponyfill and found it unsuitable for prod as it can't be webpacked.