Skip to content

Fix a bunch of little issues with the new auth API #3999

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 8 commits into from
Dec 3, 2020
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
2 changes: 1 addition & 1 deletion common/api-review/auth-exp.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ActionCodeURL implements externs.ActionCodeURL {
// (undocumented)
readonly languageCode: string | null;
// (undocumented)
readonly operation: externs.Operation;
readonly operation: externs.ActionCodeOperation;
// (undocumented)
static parseLink(link: string): externs.ActionCodeURL | null;
// (undocumented)
Expand Down
25 changes: 25 additions & 0 deletions docs-exp/auth-types.actioncodeoperation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@firebase/auth-types](./auth-types.md) &gt; [ActionCodeOperation](./auth-types.actioncodeoperation.md)

## ActionCodeOperation enum

An enumeration of the possible email action types.

<b>Signature:</b>

```typescript
export const enum ActionCodeOperation
```

## Enumeration Members

| Member | Value | Description |
| --- | --- | --- |
| EMAIL\_SIGNIN | <code>'EMAIL_SIGNIN'</code> | The email link sign-in action. |
| PASSWORD\_RESET | <code>'PASSWORD_RESET'</code> | The password reset action. |
| RECOVER\_EMAIL | <code>'RECOVER_EMAIL'</code> | The email revocation action. |
| REVERT\_SECOND\_FACTOR\_ADDITION | <code>'REVERT_SECOND_FACTOR_ADDITION'</code> | The revert second factor addition email action. |
| VERIFY\_AND\_CHANGE\_EMAIL | <code>'VERIFY_AND_CHANGE_EMAIL'</code> | The revert second factor addition email action. |
| VERIFY\_EMAIL | <code>'VERIFY_EMAIL'</code> | The email verification action. |

13 changes: 7 additions & 6 deletions packages-exp/auth-compat-exp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ function registerAuthCompat(instance: _FirebaseNamespace): void {
.setServiceProps({
ActionCodeInfo: {
Operation: {
EMAIL_SIGNIN: externs.Operation.EMAIL_SIGNIN,
PASSWORD_RESET: externs.Operation.PASSWORD_RESET,
RECOVER_EMAIL: externs.Operation.RECOVER_EMAIL,
EMAIL_SIGNIN: externs.ActionCodeOperation.EMAIL_SIGNIN,
PASSWORD_RESET: externs.ActionCodeOperation.PASSWORD_RESET,
RECOVER_EMAIL: externs.ActionCodeOperation.RECOVER_EMAIL,
REVERT_SECOND_FACTOR_ADDITION:
externs.Operation.REVERT_SECOND_FACTOR_ADDITION,
VERIFY_AND_CHANGE_EMAIL: externs.Operation.VERIFY_AND_CHANGE_EMAIL,
VERIFY_EMAIL: externs.Operation.VERIFY_EMAIL
externs.ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION,
VERIFY_AND_CHANGE_EMAIL:
externs.ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL,
VERIFY_EMAIL: externs.ActionCodeOperation.VERIFY_EMAIL
}
},
EmailAuthProvider: impl.EmailAuthProvider,
Expand Down
1 change: 1 addition & 0 deletions packages-exp/auth-exp/demo/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
src/config.js
.firebaserc
.firebase
public/service-worker.*
public/web-worker.*
public/index.js*
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Operation, Auth } from '@firebase/auth-types-exp';
import { ActionCodeOperation, Auth } from '@firebase/auth-types-exp';

import { Endpoint, HttpMethod, _performApiRequest } from '../index';
import { IdTokenResponse } from '../../model/id_token';
Expand All @@ -29,7 +29,7 @@ export interface ResetPasswordRequest {
export interface ResetPasswordResponse {
email: string;
newEmail?: string;
requestType?: Operation;
requestType?: ActionCodeOperation;
mfaInfo?: MfaEnrollment;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { expect, use } from 'chai';
import * as chaiAsPromised from 'chai-as-promised';

import { Operation } from '@firebase/auth-types-exp';
import { ActionCodeOperation } from '@firebase/auth-types-exp';
import { FirebaseError } from '@firebase/util';

import { Endpoint, HttpHeader } from '../';
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('api/authentication/signInWithPassword', () => {

describe('api/authentication/sendEmailVerification', () => {
const request: VerifyEmailRequest = {
requestType: Operation.VERIFY_EMAIL,
requestType: ActionCodeOperation.VERIFY_EMAIL,
idToken: 'my-token'
};

Expand Down Expand Up @@ -159,7 +159,7 @@ describe('api/authentication/sendEmailVerification', () => {

describe('api/authentication/sendPasswordResetEmail', () => {
const request: PasswordResetRequest = {
requestType: Operation.PASSWORD_RESET,
requestType: ActionCodeOperation.PASSWORD_RESET,
email: '[email protected]'
};

Expand Down Expand Up @@ -216,7 +216,7 @@ describe('api/authentication/sendPasswordResetEmail', () => {

describe('api/authentication/sendSignInLinkToEmail', () => {
const request: EmailSignInRequest = {
requestType: Operation.EMAIL_SIGNIN,
requestType: ActionCodeOperation.EMAIL_SIGNIN,
email: '[email protected]'
};

Expand Down Expand Up @@ -273,7 +273,7 @@ describe('api/authentication/sendSignInLinkToEmail', () => {

describe('api/authentication/verifyAndChangeEmail', () => {
const request: VerifyAndChangeEmailRequest = {
requestType: Operation.VERIFY_AND_CHANGE_EMAIL,
requestType: ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL,
idToken: 'id-token',
newEmail: '[email protected]'
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Operation, Auth } from '@firebase/auth-types-exp';
import { ActionCodeOperation, Auth } from '@firebase/auth-types-exp';

import {
Endpoint,
Expand Down Expand Up @@ -61,23 +61,23 @@ export interface GetOobCodeRequest {
}

export interface VerifyEmailRequest extends GetOobCodeRequest {
requestType: Operation.VERIFY_EMAIL;
requestType: ActionCodeOperation.VERIFY_EMAIL;
idToken: IdToken;
}

export interface PasswordResetRequest extends GetOobCodeRequest {
requestType: Operation.PASSWORD_RESET;
requestType: ActionCodeOperation.PASSWORD_RESET;
email: string;
captchaResp?: string;
}

export interface EmailSignInRequest extends GetOobCodeRequest {
requestType: Operation.EMAIL_SIGNIN;
requestType: ActionCodeOperation.EMAIL_SIGNIN;
email: string;
}

export interface VerifyAndChangeEmailRequest extends GetOobCodeRequest {
requestType: Operation.VERIFY_AND_CHANGE_EMAIL;
requestType: ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL;
idToken: IdToken;
newEmail: string;
}
Expand Down
28 changes: 18 additions & 10 deletions packages-exp/auth-exp/src/core/action_code_url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { expect } from 'chai';

import { Operation } from '@firebase/auth-types-exp';
import { ActionCodeOperation } from '@firebase/auth-types-exp';

import { ActionCodeURL } from './action_code_url';

Expand All @@ -32,7 +32,7 @@ describe('core/action_code_url', () => {
encodeURIComponent(continueUrl) +
'&languageCode=en&tenantId=TENANT_ID&state=bla';
const actionCodeUrl = ActionCodeURL.parseLink(actionLink);
expect(actionCodeUrl!.operation).to.eq(Operation.EMAIL_SIGNIN);
expect(actionCodeUrl!.operation).to.eq(ActionCodeOperation.EMAIL_SIGNIN);
expect(actionCodeUrl!.code).to.eq('CODE');
expect(actionCodeUrl!.apiKey).to.eq('API_KEY');
// ContinueUrl should be decoded.
Expand All @@ -48,7 +48,9 @@ describe('core/action_code_url', () => {
'oobCode=CODE&mode=signIn&apiKey=API_KEY&' +
'languageCode=en';
const actionCodeUrl = ActionCodeURL.parseLink(actionLink);
expect(actionCodeUrl!.operation).to.eq(Operation.EMAIL_SIGNIN);
expect(actionCodeUrl!.operation).to.eq(
ActionCodeOperation.EMAIL_SIGNIN
);
});

it('should identitfy VERIFY_AND_CHANGE_EMAIL', () => {
Expand All @@ -58,7 +60,7 @@ describe('core/action_code_url', () => {
'languageCode=en';
const actionCodeUrl = ActionCodeURL.parseLink(actionLink);
expect(actionCodeUrl!.operation).to.eq(
Operation.VERIFY_AND_CHANGE_EMAIL
ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL
);
});

Expand All @@ -68,7 +70,9 @@ describe('core/action_code_url', () => {
'oobCode=CODE&mode=verifyEmail&apiKey=API_KEY&' +
'languageCode=en';
const actionCodeUrl = ActionCodeURL.parseLink(actionLink);
expect(actionCodeUrl!.operation).to.eq(Operation.VERIFY_EMAIL);
expect(actionCodeUrl!.operation).to.eq(
ActionCodeOperation.VERIFY_EMAIL
);
});

it('should identitfy RECOVER_EMAIL', () => {
Expand All @@ -77,7 +81,9 @@ describe('core/action_code_url', () => {
'oobCode=CODE&mode=recoverEmail&apiKey=API_KEY&' +
'languageCode=en';
const actionCodeUrl = ActionCodeURL.parseLink(actionLink);
expect(actionCodeUrl!.operation).to.eq(Operation.RECOVER_EMAIL);
expect(actionCodeUrl!.operation).to.eq(
ActionCodeOperation.RECOVER_EMAIL
);
});

it('should identitfy PASSWORD_RESET', () => {
Expand All @@ -86,7 +92,9 @@ describe('core/action_code_url', () => {
'oobCode=CODE&mode=resetPassword&apiKey=API_KEY&' +
'languageCode=en';
const actionCodeUrl = ActionCodeURL.parseLink(actionLink);
expect(actionCodeUrl!.operation).to.eq(Operation.PASSWORD_RESET);
expect(actionCodeUrl!.operation).to.eq(
ActionCodeOperation.PASSWORD_RESET
);
});

it('should identitfy REVERT_SECOND_FACTOR_ADDITION', () => {
Expand All @@ -96,7 +104,7 @@ describe('core/action_code_url', () => {
'languageCode=en';
const actionCodeUrl = ActionCodeURL.parseLink(actionLink);
expect(actionCodeUrl!.operation).to.eq(
Operation.REVERT_SECOND_FACTOR_ADDITION
ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION
);
});
});
Expand All @@ -106,7 +114,7 @@ describe('core/action_code_url', () => {
'https://www.example.com:8080/finishSignIn?' +
'oobCode=CODE&mode=signIn&apiKey=API_KEY&state=bla';
const actionCodeUrl = ActionCodeURL.parseLink(actionLink);
expect(actionCodeUrl!.operation).to.eq(Operation.EMAIL_SIGNIN);
expect(actionCodeUrl!.operation).to.eq(ActionCodeOperation.EMAIL_SIGNIN);
expect(actionCodeUrl!.code).to.eq('CODE');
expect(actionCodeUrl!.apiKey).to.eq('API_KEY');
expect(actionCodeUrl!.continueUrl).to.be.null;
Expand All @@ -120,7 +128,7 @@ describe('core/action_code_url', () => {
'oobCode=CODE1&mode=signIn&apiKey=API_KEY1&state=bla' +
'#oobCode=CODE2&mode=signIn&apiKey=API_KEY2&state=bla';
const actionCodeUrl = ActionCodeURL.parseLink(actionLink);
expect(actionCodeUrl!.operation).to.eq(Operation.EMAIL_SIGNIN);
expect(actionCodeUrl!.operation).to.eq(ActionCodeOperation.EMAIL_SIGNIN);
expect(actionCodeUrl!.code).to.eq('CODE1');
expect(actionCodeUrl!.apiKey).to.eq('API_KEY1');
expect(actionCodeUrl!.continueUrl).to.be.null;
Expand Down
16 changes: 8 additions & 8 deletions packages-exp/auth-exp/src/core/action_code_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ const enum QueryField {
* @param mode
* @internal
*/
function parseMode(mode: string | null): externs.Operation | null {
function parseMode(mode: string | null): externs.ActionCodeOperation | null {
switch (mode) {
case 'recoverEmail':
return externs.Operation.RECOVER_EMAIL;
return externs.ActionCodeOperation.RECOVER_EMAIL;
case 'resetPassword':
return externs.Operation.PASSWORD_RESET;
return externs.ActionCodeOperation.PASSWORD_RESET;
case 'signIn':
return externs.Operation.EMAIL_SIGNIN;
return externs.ActionCodeOperation.EMAIL_SIGNIN;
case 'verifyEmail':
return externs.Operation.VERIFY_EMAIL;
return externs.ActionCodeOperation.VERIFY_EMAIL;
case 'verifyAndChangeEmail':
return externs.Operation.VERIFY_AND_CHANGE_EMAIL;
return externs.ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL;
case 'revertSecondFactorAddition':
return externs.Operation.REVERT_SECOND_FACTOR_ADDITION;
return externs.ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION;
default:
return null;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ export class ActionCodeURL implements externs.ActionCodeURL {
/** {@inheritDoc @firebase/auth-types#ActionCodeURL.languageCode} */
readonly languageCode: string | null;
/** {@inheritDoc @firebase/auth-types#ActionCodeURL.operation} */
readonly operation: externs.Operation;
readonly operation: externs.ActionCodeOperation;
/** {@inheritDoc @firebase/auth-types#ActionCodeURL.tenantId} */
readonly tenantId: string | null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ describe('core/strategies/credential', () => {
const error = await expect(
signInWithCredential(auth, authCredential)
).to.be.rejectedWith(MultiFactorError);
expect(error.credential).to.eq(authCredential);
expect(error.operationType).to.eq(OperationType.SIGN_IN);
expect(error.serverResponse).to.eql(serverResponse);
expect(error.user).to.be.undefined;
Expand Down
Loading