Skip to content

Commit a75b407

Browse files
committed
Fix some issues
1 parent e13c132 commit a75b407

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,13 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
296296
}
297297

298298
async updateCurrentUser(userExtern: User | null): Promise<void> {
299-
// The public updateCurrentUser method needs to make a copy of the user
299+
// The public updateCurrentUser method needs to make a copy of the user,
300+
// and also check that the project matches
300301
const user = userExtern as UserInternal | null;
301-
return this._updateCurrentUser(user && user._clone());
302+
if (user) {
303+
_assert(user.auth.config.apiKey === this.config.apiKey, this, AuthErrorCode.INVALID_AUTH);
304+
}
305+
return this._updateCurrentUser(user && user._clone(this));
302306
}
303307

304308
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)