Skip to content

Commit 976c5b1

Browse files
authored
[Auth] Fix an issue with the UI interop (#4688)
* Fix interop issue * Formatting * Fix some issues * Formatting
1 parent 62b5e22 commit 976c5b1

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

packages-exp/auth-compat-exp/demo/rollup.config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import commonjs from '@rollup/plugin-commonjs';
1918
import json from '@rollup/plugin-json';
2019
import resolveModule from '@rollup/plugin-node-resolve';
2120
import sourcemaps from 'rollup-plugin-sourcemaps';
@@ -29,8 +28,7 @@ const plugins = [
2928
typescript,
3029
include: ['../**/*.ts']
3130
}),
32-
json(),
33-
commonjs()
31+
json()
3432
];
3533

3634
/**

packages-exp/auth-exp/src/core/auth/auth_impl.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ describe('core/auth/auth_impl', () => {
8585

8686
it('public version throws if the auth is mismatched', async () => {
8787
const auth2 = await testAuth();
88-
Object.assign(auth2, { name: 'not-the-right-auth' });
88+
Object.assign(auth2.config, { apiKey: 'not-the-right-auth' });
8989
const user = testUser(auth2, 'uid');
9090
await expect(auth.updateCurrentUser(user)).to.be.rejectedWith(
9191
FirebaseError,
92-
'auth/argument-error'
92+
'auth/invalid-user-token'
9393
);
9494
});
9595

packages-exp/auth-exp/src/core/auth/auth_impl.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,16 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
297297

298298
async updateCurrentUser(userExtern: User | null): Promise<void> {
299299
// The public updateCurrentUser method needs to make a copy of the user,
300-
// and also needs to verify that the app matches
300+
// and also check that the project matches
301301
const user = userExtern as UserInternal | null;
302-
_assert(
303-
!user || user.auth.name === this.name,
304-
this,
305-
AuthErrorCode.ARGUMENT_ERROR
306-
);
307-
308-
return this._updateCurrentUser(user && user._clone());
302+
if (user) {
303+
_assert(
304+
user.auth.config.apiKey === this.config.apiKey,
305+
this,
306+
AuthErrorCode.INVALID_AUTH
307+
);
308+
}
309+
return this._updateCurrentUser(user && user._clone(this));
309310
}
310311

311312
async _updateCurrentUser(user: User | null): Promise<void> {

packages-exp/auth-exp/src/core/user/user_impl.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ describe('core/user/user_impl', () => {
244244
});
245245

246246
describe('_clone', () => {
247-
it('copies the user to a new object', () => {
247+
it('copies the user to a new object', async () => {
248248
const stsTokenManager = Object.assign(new StsTokenManager(), {
249249
accessToken: 'access-token',
250250
refreshToken: 'refresh-token',
@@ -263,10 +263,12 @@ describe('core/user/user_impl', () => {
263263
isAnonymous: true
264264
});
265265

266-
const copy = user._clone();
266+
const newAuth = await testAuth();
267+
const copy = user._clone(newAuth);
267268
expect(copy).not.to.eq(user);
268269
expect(copy.stsTokenManager).not.to.eq(user.stsTokenManager);
269270
expect(copy.toJSON()).to.eql(user.toJSON());
271+
expect(copy.auth).to.eq(newAuth);
270272
});
271273
});
272274
});

packages-exp/auth-exp/src/core/user/user_impl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ export class UserImpl implements UserInternal {
135135
this.stsTokenManager._assign(user.stsTokenManager);
136136
}
137137

138-
_clone(): UserInternal {
138+
_clone(auth: AuthInternal): UserInternal {
139139
return new UserImpl({
140140
...this,
141+
auth,
141142
stsTokenManager: this.stsTokenManager._clone()
142143
});
143144
}

packages-exp/auth-exp/src/model/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export interface UserInternal extends User {
7575
): Promise<void>;
7676

7777
_assign(user: UserInternal): void;
78-
_clone(): UserInternal;
78+
_clone(auth: AuthInternal): UserInternal;
7979
_onReload: (cb: NextFn<APIUserInfo>) => void;
8080
_notifyReloadListener: NextFn<APIUserInfo>;
8181
_startProactiveRefresh: () => void;

0 commit comments

Comments
 (0)