Skip to content

feat(auth): Adds support to specifying Auth state persistence. #105

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 4 commits into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 72 additions & 2 deletions externs/firebase-auth-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ firebase.UserInfo.prototype.displayName;
*/
firebase.UserInfo.prototype.photoURL;

/**
* The user's E.164 formatted phone number (if available).
*
* @type {?string}
*/
firebase.UserInfo.prototype.phoneNumber;

/**
* A user account.
*
Expand Down Expand Up @@ -480,7 +487,7 @@ firebase.User.prototype.reauthenticateWithCredential = function(credential) {};
* </dl>
*
* @param {!firebase.auth.AuthCredential} credential
* @return {!firebase.Promise<void>}
* @return {!firebase.Promise<!firebase.auth.UserCredential>}
Copy link
Contributor

Choose a reason for hiding this comment

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

This same change should be made in the typings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Typings were autoimported from externs (same for below)

*/
firebase.User.prototype.reauthenticateAndRetrieveDataWithCredential =
function(credential) {};
Expand Down Expand Up @@ -787,6 +794,69 @@ firebase.auth.Auth.prototype.app;
*/
firebase.auth.Auth.prototype.currentUser;

/**
* @enum {string}
* An enumeration of the possible persistence mechanism types.
*/
firebase.auth.Auth.Persistence = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, this should also be in the typings.

/**
* Indicates that the state will be persisted even when the browser window is
* closed or the activity is destroyed in react-native.
*/
LOCAL: 'local',
/**
* Indicates that the state will only be stored in memory and will be cleared
* when the window or activity is refreshed.
*/
NONE: 'none',
/**
* Indicates that the state will only persist in current session/tab, relevant
* to web only, and will be cleared when the tab is closed.
*/
SESSION: 'session'
};

/**
* Changes the current type of persistence on the current Auth instance for the
* currently saved Auth session and applies this type of persistence for
* future sign-in requests, including sign-in with redirect requests. This will
* return a promise that will resolve once the state finishes copying from one
* type of storage to the other.
* Calling a sign-in method after changing persistence will wait for that
* persistence change to complete before applying it on the new Auth state.
*
* This makes it easy for a user signing in to specify whether their session
* should be remembered or not. It also makes it easier to never persist the
* Auth state for applications that are shared by other users or have sensitive
* data.
*
* The default for web browser apps and React Native apps is 'local' (provided
* the browser supports this mechanism) whereas it is 'none' for Node.js backend
* apps.
*
* <h4>Error Codes (thrown synchronously)</h4>
* <dl>
* <dt>auth/invalid-persistence-type</dt>
* <dd>Thrown if the specified persistence type is invalid.</dd>
* <dt>auth/unsupported-persistence-type</dt>
* <dd>Thrown if the current environment does not support the specified
* persistence type.</dd>
* </dl>
*
* @example
* firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
* .then(function() {
* // Existing and future Auth states are now persisted in the current
* // session only. Closing the window would clear any existing state even if
* // a user forgets to sign out.
* });
*
* @param {!firebase.auth.Auth.Persistence} persistence The auth state
* persistence mechanism.
* @return {!firebase.Promise<void>}
*/
firebase.auth.Auth.prototype.setPersistence = function(persistence) {};

/**
* Creates a new user account associated with the specified email address and
* password.
Expand Down Expand Up @@ -1871,4 +1941,4 @@ firebase.auth.ApplicationVerifier.prototype.type;
* @return {!firebase.Promise<string>} A Promise for a token that can be used to
* assert the validity of a request.
*/
firebase.auth.ApplicationVerifier.prototype.verify = function() {};
firebase.auth.ApplicationVerifier.prototype.verify = function() {};
Loading