Skip to content

Commit c58719c

Browse files
bojeil-googlejshcrowthe
authored andcommitted
feat(auth): Adds support to specifying Auth state persistence. (#105)
* feat(auth): Adds support to specifying Auth state persistence. fix(auth): Adds missing phoneNumber property in UserInfo. fix(auth): Fixes incorrect return type in reauthenticateAndRetrieveDataWithCredential. * docs(*): automatic .d.ts update from externs * feat(auth): import from auth source
1 parent bc1f67c commit c58719c

File tree

4 files changed

+411
-310
lines changed

4 files changed

+411
-310
lines changed

externs/firebase-auth-externs.js

+72-2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ firebase.UserInfo.prototype.displayName;
130130
*/
131131
firebase.UserInfo.prototype.photoURL;
132132

133+
/**
134+
* The user's E.164 formatted phone number (if available).
135+
*
136+
* @type {?string}
137+
*/
138+
firebase.UserInfo.prototype.phoneNumber;
139+
133140
/**
134141
* A user account.
135142
*
@@ -480,7 +487,7 @@ firebase.User.prototype.reauthenticateWithCredential = function(credential) {};
480487
* </dl>
481488
*
482489
* @param {!firebase.auth.AuthCredential} credential
483-
* @return {!firebase.Promise<void>}
490+
* @return {!firebase.Promise<!firebase.auth.UserCredential>}
484491
*/
485492
firebase.User.prototype.reauthenticateAndRetrieveDataWithCredential =
486493
function(credential) {};
@@ -787,6 +794,69 @@ firebase.auth.Auth.prototype.app;
787794
*/
788795
firebase.auth.Auth.prototype.currentUser;
789796

797+
/**
798+
* @enum {string}
799+
* An enumeration of the possible persistence mechanism types.
800+
*/
801+
firebase.auth.Auth.Persistence = {
802+
/**
803+
* Indicates that the state will be persisted even when the browser window is
804+
* closed or the activity is destroyed in react-native.
805+
*/
806+
LOCAL: 'local',
807+
/**
808+
* Indicates that the state will only be stored in memory and will be cleared
809+
* when the window or activity is refreshed.
810+
*/
811+
NONE: 'none',
812+
/**
813+
* Indicates that the state will only persist in current session/tab, relevant
814+
* to web only, and will be cleared when the tab is closed.
815+
*/
816+
SESSION: 'session'
817+
};
818+
819+
/**
820+
* Changes the current type of persistence on the current Auth instance for the
821+
* currently saved Auth session and applies this type of persistence for
822+
* future sign-in requests, including sign-in with redirect requests. This will
823+
* return a promise that will resolve once the state finishes copying from one
824+
* type of storage to the other.
825+
* Calling a sign-in method after changing persistence will wait for that
826+
* persistence change to complete before applying it on the new Auth state.
827+
*
828+
* This makes it easy for a user signing in to specify whether their session
829+
* should be remembered or not. It also makes it easier to never persist the
830+
* Auth state for applications that are shared by other users or have sensitive
831+
* data.
832+
*
833+
* The default for web browser apps and React Native apps is 'local' (provided
834+
* the browser supports this mechanism) whereas it is 'none' for Node.js backend
835+
* apps.
836+
*
837+
* <h4>Error Codes (thrown synchronously)</h4>
838+
* <dl>
839+
* <dt>auth/invalid-persistence-type</dt>
840+
* <dd>Thrown if the specified persistence type is invalid.</dd>
841+
* <dt>auth/unsupported-persistence-type</dt>
842+
* <dd>Thrown if the current environment does not support the specified
843+
* persistence type.</dd>
844+
* </dl>
845+
*
846+
* @example
847+
* firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
848+
* .then(function() {
849+
* // Existing and future Auth states are now persisted in the current
850+
* // session only. Closing the window would clear any existing state even if
851+
* // a user forgets to sign out.
852+
* });
853+
*
854+
* @param {!firebase.auth.Auth.Persistence} persistence The auth state
855+
* persistence mechanism.
856+
* @return {!firebase.Promise<void>}
857+
*/
858+
firebase.auth.Auth.prototype.setPersistence = function(persistence) {};
859+
790860
/**
791861
* Creates a new user account associated with the specified email address and
792862
* password.
@@ -1871,4 +1941,4 @@ firebase.auth.ApplicationVerifier.prototype.type;
18711941
* @return {!firebase.Promise<string>} A Promise for a token that can be used to
18721942
* assert the validity of a request.
18731943
*/
1874-
firebase.auth.ApplicationVerifier.prototype.verify = function() {};
1944+
firebase.auth.ApplicationVerifier.prototype.verify = function() {};

0 commit comments

Comments
 (0)