Skip to content

Commit c9959d4

Browse files
committed
[AUTOMATED]: Prettier Code Styling
1 parent 0f8a4ac commit c9959d4

File tree

6 files changed

+124
-56
lines changed

6 files changed

+124
-56
lines changed

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import { browserLocalPersistence } from '../persistence/browser';
3030
import { inMemoryPersistence } from '../persistence/in_memory';
3131
import { PersistenceUserManager } from '../persistence/persistence_user_manager';
3232
import { ClientPlatform, getClientVersion } from '../util/version';
33-
import { DEFAULT_API_HOST, DEFAULT_API_SCHEME, initializeAuth } from './auth_impl';
33+
import {
34+
DEFAULT_API_HOST,
35+
DEFAULT_API_SCHEME,
36+
initializeAuth
37+
} from './auth_impl';
3438

3539
use(sinonChai);
3640

@@ -119,7 +123,7 @@ describe('AuthImpl', () => {
119123
// // Helpers to convert auth state change results to promise
120124
// function onAuthStateChange(callback: NextFn<User|null>)
121125

122-
it('immediately calls authStateChange if initialization finished', (done) => {
126+
it('immediately calls authStateChange if initialization finished', done => {
123127
const user = testUser('uid');
124128
auth.currentUser = user;
125129
auth._isInitialized = true;
@@ -128,8 +132,8 @@ describe('AuthImpl', () => {
128132
done();
129133
});
130134
});
131-
132-
it('immediately calls idTokenChange if initialization finished', (done) => {
135+
136+
it('immediately calls idTokenChange if initialization finished', done => {
133137
const user = testUser('uid');
134138
auth.currentUser = user;
135139
auth._isInitialized = true;

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

+45-19
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
import { getApp } from '@firebase/app-exp';
1919
import { FirebaseApp } from '@firebase/app-types-exp';
2020
import {
21-
CompleteFn, createSubscribe, ErrorFn, NextFn, Observer, Subscribe, Unsubscribe
21+
CompleteFn,
22+
createSubscribe,
23+
ErrorFn,
24+
NextFn,
25+
Observer,
26+
Subscribe,
27+
Unsubscribe
2228
} from '@firebase/util';
2329

2430
import { Auth, Config, Dependencies, NextOrObserver } from '../../model/auth';
@@ -43,10 +49,10 @@ class AuthImpl implements Auth {
4349
private authStateSubscription = new Subscription<User>(this);
4450
private idTokenSubscription = new Subscription<User>(this);
4551
_isInitialized = false;
46-
52+
4753
// Tracks the last notified UID for state change listeners to prevent
4854
// repeated calls to the callbacks
49-
private lastNotifiedUid: string|undefined = undefined;
55+
private lastNotifiedUid: string | undefined = undefined;
5056

5157
constructor(
5258
public readonly name: string,
@@ -87,16 +93,30 @@ class AuthImpl implements Auth {
8793
});
8894
}
8995

90-
onAuthStateChanged(nextOrObserver: NextOrObserver<User>,
96+
onAuthStateChanged(
97+
nextOrObserver: NextOrObserver<User>,
9198
error?: ErrorFn,
92-
completed?: CompleteFn): Unsubscribe {
93-
return this.registerStateListener(this.authStateSubscription, nextOrObserver, error, completed);
99+
completed?: CompleteFn
100+
): Unsubscribe {
101+
return this.registerStateListener(
102+
this.authStateSubscription,
103+
nextOrObserver,
104+
error,
105+
completed
106+
);
94107
}
95108

96-
onIdTokenChange(nextOrObserver: NextOrObserver<User>,
109+
onIdTokenChange(
110+
nextOrObserver: NextOrObserver<User>,
97111
error?: ErrorFn,
98-
completed?: CompleteFn): Unsubscribe {
99-
return this.registerStateListener(this.idTokenSubscription, nextOrObserver, error, completed);
112+
completed?: CompleteFn
113+
): Unsubscribe {
114+
return this.registerStateListener(
115+
this.idTokenSubscription,
116+
nextOrObserver,
117+
error,
118+
completed
119+
);
100120
}
101121

102122
_notifyStateListeners(): void {
@@ -112,16 +132,22 @@ class AuthImpl implements Auth {
112132
}
113133
}
114134

115-
private registerStateListener(subscription: Subscription<User>, nextOrObserver: NextOrObserver<User>,
135+
private registerStateListener(
136+
subscription: Subscription<User>,
137+
nextOrObserver: NextOrObserver<User>,
116138
error?: ErrorFn,
117-
completed?: CompleteFn): Unsubscribe {
139+
completed?: CompleteFn
140+
): Unsubscribe {
118141
if (this._isInitialized) {
119-
const cb = typeof nextOrObserver === 'function' ? nextOrObserver : nextOrObserver.next;
120-
// The callback needs to be called asynchronously per the spec.
142+
const cb =
143+
typeof nextOrObserver === 'function'
144+
? nextOrObserver
145+
: nextOrObserver.next;
146+
// The callback needs to be called asynchronously per the spec.
121147
// eslint-disable-next-line @typescript-eslint/no-floating-promises
122148
Promise.resolve().then(() => cb(this.currentUser));
123149
}
124-
150+
125151
if (typeof nextOrObserver === 'function') {
126152
return subscription.addObserver(nextOrObserver, error, completed);
127153
} else {
@@ -180,15 +206,15 @@ export function initializeAuth(
180206

181207
/** Helper class to wrap subscriber logic */
182208
class Subscription<T> {
183-
private observer: Observer<T|null> | null = null;
184-
readonly addObserver: Subscribe<T|null> = createSubscribe(
185-
observer => this.observer = observer,
209+
private observer: Observer<T | null> | null = null;
210+
readonly addObserver: Subscribe<T | null> = createSubscribe(
211+
observer => (this.observer = observer)
186212
);
187213

188214
constructor(readonly auth: Auth) {}
189215

190-
get next(): NextFn<T|null> {
216+
get next(): NextFn<T | null> {
191217
const observer = assert(this.observer, this.auth.name);
192218
return observer.next.bind(observer);
193219
}
194-
}
220+
}

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

+35-20
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import { mockEndpoint } from '../../../test/api/helper';
2424
import { testUser } from '../../../test/mock_auth';
2525
import * as fetch from '../../../test/mock_fetch';
2626
import { Endpoint } from '../../api';
27-
import { APIUserInfo, ProviderUserInfo } from '../../api/account_management/account';
27+
import {
28+
APIUserInfo,
29+
ProviderUserInfo
30+
} from '../../api/account_management/account';
2831
import { UserInfo } from '../../model/user';
2932
import { ProviderId } from '../providers';
3033
import { _reloadWithoutSaving, reload } from './reload';
@@ -38,7 +41,7 @@ const BASIC_USER_INFO: UserInfo = {
3841
email: 'email',
3942
displayName: 'displayName',
4043
phoneNumber: 'phoneNumber',
41-
photoURL: 'photoURL',
44+
photoURL: 'photoURL'
4245
};
4346

4447
const BASIC_PROVIDER_USER_INFO: ProviderUserInfo = {
@@ -47,7 +50,7 @@ const BASIC_PROVIDER_USER_INFO: ProviderUserInfo = {
4750
email: 'email',
4851
displayName: 'displayName',
4952
phoneNumber: 'phoneNumber',
50-
photoUrl: 'photoURL',
53+
photoUrl: 'photoURL'
5154
};
5255

5356
describe('reload()', () => {
@@ -64,11 +67,11 @@ describe('reload()', () => {
6467
phoneNumber: 'phoneNumber',
6568
tenantId: 'tenantId',
6669
createdAt: 123,
67-
lastLoginAt: 456,
70+
lastLoginAt: 456
6871
};
6972

7073
mockEndpoint(Endpoint.GET_ACCOUNT_INFO, {
71-
users: [serverUser],
74+
users: [serverUser]
7275
});
7376

7477
const user = testUser('abc', '', true);
@@ -82,22 +85,26 @@ describe('reload()', () => {
8285
expect(user.tenantId).to.eq('tenantId');
8386
expect(user.metadata).to.eql({
8487
creationTime: '123',
85-
lastSignInTime: '456',
88+
lastSignInTime: '456'
8689
});
8790
});
8891

8992
it('adds missing provider data', async () => {
9093
const user = testUser('abc', '', true);
91-
user.providerData = [{...BASIC_USER_INFO}];
94+
user.providerData = [{ ...BASIC_USER_INFO }];
9295
mockEndpoint(Endpoint.GET_ACCOUNT_INFO, {
93-
users: [{
94-
providerUserInfo: [{...BASIC_PROVIDER_USER_INFO, providerId: ProviderId.FACEBOOK}],
95-
}],
96+
users: [
97+
{
98+
providerUserInfo: [
99+
{ ...BASIC_PROVIDER_USER_INFO, providerId: ProviderId.FACEBOOK }
100+
]
101+
}
102+
]
96103
});
97104
await _reloadWithoutSaving(user);
98105
expect(user.providerData).to.eql([
99-
{...BASIC_USER_INFO},
100-
{...BASIC_USER_INFO, providerId: ProviderId.FACEBOOK},
106+
{ ...BASIC_USER_INFO },
107+
{ ...BASIC_USER_INFO, providerId: ProviderId.FACEBOOK }
101108
]);
102109
});
103110

@@ -107,32 +114,40 @@ describe('reload()', () => {
107114
{
108115
...BASIC_USER_INFO,
109116
providerId: ProviderId.GITHUB,
110-
uid: 'i-will-be-overwritten',
117+
uid: 'i-will-be-overwritten'
111118
},
112119
{
113120
...BASIC_USER_INFO
114121
}
115122
];
116123
mockEndpoint(Endpoint.GET_ACCOUNT_INFO, {
117-
users: [{
118-
providerUserInfo: [{...BASIC_PROVIDER_USER_INFO, providerId: ProviderId.GITHUB, rawId: 'new-uid'}],
119-
}],
124+
users: [
125+
{
126+
providerUserInfo: [
127+
{
128+
...BASIC_PROVIDER_USER_INFO,
129+
providerId: ProviderId.GITHUB,
130+
rawId: 'new-uid'
131+
}
132+
]
133+
}
134+
]
120135
});
121136
await _reloadWithoutSaving(user);
122137
console.warn(user.providerData);
123138
expect(user.providerData).to.eql([
124-
{...BASIC_USER_INFO},
139+
{ ...BASIC_USER_INFO },
125140
{
126141
...BASIC_USER_INFO,
127142
providerId: ProviderId.GITHUB,
128-
uid: 'new-uid',
129-
},
143+
uid: 'new-uid'
144+
}
130145
]);
131146
});
132147

133148
it('reload calls auth.updateCurrentUser after completion', async () => {
134149
mockEndpoint(Endpoint.GET_ACCOUNT_INFO, {
135-
users: [{}],
150+
users: [{}]
136151
});
137152

138153
const user = testUser('user', '', true);

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { getAccountInfo, ProviderUserInfo } from '../../api/account_management/account';
18+
import {
19+
getAccountInfo,
20+
ProviderUserInfo
21+
} from '../../api/account_management/account';
1922
import { User, UserInfo } from '../../model/user';
2023
import { ProviderId } from '../providers';
2124
import { assert } from '../util/assert';
2225

23-
export async function _reloadWithoutSaving(
24-
user: User
25-
): Promise<void> {
26+
export async function _reloadWithoutSaving(user: User): Promise<void> {
2627
const auth = user.auth;
2728
const idToken = await user.getIdToken();
2829
const response = await getAccountInfo(auth, { idToken });

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

+18-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { CompleteFn, ErrorFn, NextFn, Observer, Unsubscribe } from '@firebase/util';
18+
import {
19+
CompleteFn,
20+
ErrorFn,
21+
NextFn,
22+
Observer,
23+
Unsubscribe
24+
} from '@firebase/util';
1925

2026
import { Persistence } from '../core/persistence';
2127
import { User } from './user';
2228

2329
export type AppName = string;
2430
export type ApiKey = string;
2531
export type AuthDomain = string;
26-
export type NextOrObserver<T> = NextFn<T|null> | Observer<T|null>;
32+
export type NextOrObserver<T> = NextFn<T | null> | Observer<T | null>;
2733

2834
export interface Config {
2935
apiKey: ApiKey;
@@ -42,8 +48,16 @@ export interface Auth {
4248
setPersistence(persistence: Persistence): Promise<void>;
4349
updateCurrentUser(user: User | null): Promise<void>;
4450
signOut(): Promise<void>;
45-
onAuthStateChanged(nextOrObserver: NextOrObserver<User>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
46-
onIdTokenChange(nextOrObserver: NextOrObserver<User>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
51+
onAuthStateChanged(
52+
nextOrObserver: NextOrObserver<User>,
53+
error?: ErrorFn,
54+
completed?: CompleteFn
55+
): Unsubscribe;
56+
onIdTokenChange(
57+
nextOrObserver: NextOrObserver<User>,
58+
error?: ErrorFn,
59+
completed?: CompleteFn
60+
): Unsubscribe;
4761
_notifyStateListeners(): void;
4862
}
4963

packages-exp/auth-exp/test/mock_auth.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,27 @@ export const mockAuth: Auth = {
3737
async setPersistence() {},
3838
async updateCurrentUser() {},
3939
async signOut() {},
40-
onAuthStateChanged() {return () => {};},
41-
onIdTokenChange() { return () => {};},
42-
_notifyStateListeners() {},
40+
onAuthStateChanged() {
41+
return () => {};
42+
},
43+
onIdTokenChange() {
44+
return () => {};
45+
},
46+
_notifyStateListeners() {}
4347
};
4448

45-
export function testUser(uid: string, email?: string, fakeTokens = false): User {
49+
export function testUser(
50+
uid: string,
51+
email?: string,
52+
fakeTokens = false
53+
): User {
4654
// Create a token manager that's valid off the bat to avoid refresh calls
4755
const stsTokenManager = new StsTokenManager();
4856
if (fakeTokens) {
4957
Object.assign<StsTokenManager, Partial<StsTokenManager>>(stsTokenManager, {
5058
expirationTime: Date.now() + 100_000,
5159
accessToken: 'access-token',
52-
refreshToken: 'refresh-token',
60+
refreshToken: 'refresh-token'
5361
});
5462
}
5563

0 commit comments

Comments
 (0)