Skip to content

Commit d0b6c7f

Browse files
committed
add updateEmail to methods that fail
1 parent 311bff3 commit d0b6c7f

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

docs-devsite/auth.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,8 @@ Updates the user's email address.
16481648

16491649
An email will be sent to the original email address (if it was set) that allows to revoke the email address change, in order to protect them from account hijacking.
16501650

1651+
This method is not supported on any [User](./auth.user.md#user_interface) signed in by [Auth](./auth.auth.md#auth_interface) instances created with a [FirebaseServerApp](./app.firebaseserverapp.md#firebaseserverapp_interface)<!-- -->.
1652+
16511653
Important: this is a security sensitive operation that requires the user to have recently signed in. If this requirement isn't met, ask the user to authenticate again and then call [reauthenticateWithCredential()](./auth.md#reauthenticatewithcredential_60f8043)<!-- -->.
16521654

16531655
<b>Signature:</b>

packages/auth/src/core/user/account_info.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import { UserInternal } from '../../model/user';
2626
import { _logoutIfInvalidated } from './invalidation';
2727
import { getModularInstance } from '@firebase/util';
2828
import { ProviderId } from '../../model/enums';
29+
import { _isFirebaseServerApp } from '@firebase/app';
30+
import { _createError } from '../../core/util/assert';
31+
import { AuthErrorCode } from '../../core/errors';
2932

3033
/**
3134
* Updates a user's profile data.
@@ -81,6 +84,9 @@ export async function updateProfile(
8184
* An email will be sent to the original email address (if it was set) that allows to revoke the
8285
* email address change, in order to protect them from account hijacking.
8386
*
87+
* This method is not supported on any {@link User} signed in by {@link Auth} instances
88+
* created with a {@link @firebase/app#FirebaseServerApp}.
89+
*
8490
* Important: this is a security sensitive operation that requires the user to have recently signed
8591
* in. If this requirement isn't met, ask the user to authenticate again and then call
8692
* {@link reauthenticateWithCredential}.
@@ -94,11 +100,13 @@ export async function updateProfile(
94100
* @public
95101
*/
96102
export function updateEmail(user: User, newEmail: string): Promise<void> {
97-
return updateEmailOrPassword(
98-
getModularInstance(user) as UserInternal,
99-
newEmail,
100-
null
101-
);
103+
const userInternal = getModularInstance(user) as UserInternal;
104+
if (_isFirebaseServerApp(userInternal.auth.app)) {
105+
return Promise.reject(
106+
_createError(userInternal.auth, AuthErrorCode.OPERATION_NOT_SUPPORTED)
107+
);
108+
}
109+
return updateEmailOrPassword(userInternal, newEmail, null);
102110
}
103111

104112
/**

packages/auth/test/integration/flows/firebaseserverapp.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
signInWithRedirect,
3838
signOut,
3939
updateCurrentUser,
40+
updateEmail,
4041
updateProfile
4142
} from '@firebase/auth';
4243
import { isBrowser, FirebaseError } from '@firebase/util';
@@ -513,6 +514,13 @@ describe('Integration test: Auth FirebaseServerApp tests', () => {
513514
FirebaseError,
514515
'operation-not-supported-in-this-environment'
515516
);
517+
518+
await expect(
519+
updateEmail(serverAppAuth.currentUser, email)
520+
).to.be.rejectedWith(
521+
FirebaseError,
522+
'operation-not-supported-in-this-environment'
523+
);
516524
}
517525

518526
await deleteApp(serverApp);

0 commit comments

Comments
 (0)