Skip to content

[Auth] Fix an issue with the UI interop #4688

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
Mar 31, 2021
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
4 changes: 1 addition & 3 deletions packages-exp/auth-compat-exp/demo/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import resolveModule from '@rollup/plugin-node-resolve';
import sourcemaps from 'rollup-plugin-sourcemaps';
Expand All @@ -29,8 +28,7 @@ const plugins = [
typescript,
include: ['../**/*.ts']
}),
json(),
commonjs()
json()
];

/**
Expand Down
4 changes: 2 additions & 2 deletions packages-exp/auth-exp/src/core/auth/auth_impl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ describe('core/auth/auth_impl', () => {

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

Expand Down
17 changes: 9 additions & 8 deletions packages-exp/auth-exp/src/core/auth/auth_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,16 @@ export class AuthImpl implements AuthInternal, _FirebaseService {

async updateCurrentUser(userExtern: User | null): Promise<void> {
// The public updateCurrentUser method needs to make a copy of the user,
// and also needs to verify that the app matches
// and also check that the project matches
const user = userExtern as UserInternal | null;
_assert(
!user || user.auth.name === this.name,
this,
AuthErrorCode.ARGUMENT_ERROR
);

return this._updateCurrentUser(user && user._clone());
if (user) {
_assert(
user.auth.config.apiKey === this.config.apiKey,
this,
AuthErrorCode.INVALID_AUTH
);
}
return this._updateCurrentUser(user && user._clone(this));
}

async _updateCurrentUser(user: User | null): Promise<void> {
Expand Down
6 changes: 4 additions & 2 deletions packages-exp/auth-exp/src/core/user/user_impl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ describe('core/user/user_impl', () => {
});

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

const copy = user._clone();
const newAuth = await testAuth();
const copy = user._clone(newAuth);
expect(copy).not.to.eq(user);
expect(copy.stsTokenManager).not.to.eq(user.stsTokenManager);
expect(copy.toJSON()).to.eql(user.toJSON());
expect(copy.auth).to.eq(newAuth);
});
});
});
3 changes: 2 additions & 1 deletion packages-exp/auth-exp/src/core/user/user_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ export class UserImpl implements UserInternal {
this.stsTokenManager._assign(user.stsTokenManager);
}

_clone(): UserInternal {
_clone(auth: AuthInternal): UserInternal {
return new UserImpl({
...this,
auth,
stsTokenManager: this.stsTokenManager._clone()
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages-exp/auth-exp/src/model/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export interface UserInternal extends User {
): Promise<void>;

_assign(user: UserInternal): void;
_clone(): UserInternal;
_clone(auth: AuthInternal): UserInternal;
_onReload: (cb: NextFn<APIUserInfo>) => void;
_notifyReloadListener: NextFn<APIUserInfo>;
_startProactiveRefresh: () => void;
Expand Down