Skip to content

Commit 3820e84

Browse files
Merge pull request #3470 from quadratichq/jim/fix-numberous-mixpanel-calls
fix: numerous mixpanel events for [Loading].complete
2 parents f28fba7 + c1b89e9 commit 3820e84

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

quadratic-client/src/auth/auth.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { oryClient } from '@/auth/ory';
2+
import { workosClient } from '@/auth/workos';
13
import { getOrInitializeActiveTeam } from '@/shared/utils/activeTeam';
24
import { useEffect } from 'react';
35

@@ -32,19 +34,12 @@ export interface AuthClient {
3234
authenticateWithMagicCode(args: { email: string; code: string }): Promise<void>;
3335
}
3436

35-
let cachedAuthClient: Promise<AuthClient> | AuthClient | null = null;
36-
const getAuthClient = async (): Promise<AuthClient> => {
37-
if (cachedAuthClient) {
38-
return await cachedAuthClient;
39-
}
40-
37+
const getAuthClient = (): AuthClient => {
4138
switch (AUTH_TYPE) {
4239
case 'ory':
43-
cachedAuthClient = (await import('@/auth/ory')).oryClient;
44-
return cachedAuthClient;
40+
return oryClient;
4541
case 'workos':
46-
cachedAuthClient = (await import('@/auth/workos')).workosClient;
47-
return cachedAuthClient;
42+
return workosClient;
4843
default:
4944
throw new Error(`Unsupported auth type in getAuthClient(): ${AUTH_TYPE}`);
5045
}
@@ -53,59 +48,59 @@ const getAuthClient = async (): Promise<AuthClient> => {
5348
// Create a proxy client that lazily loads the actual client
5449
export const authClient: AuthClient = {
5550
async isAuthenticated() {
56-
const client = await getAuthClient();
51+
const client = getAuthClient();
5752
return client.isAuthenticated();
5853
},
5954
async user() {
60-
const client = await getAuthClient();
55+
const client = getAuthClient();
6156
return client.user();
6257
},
6358
async login(args: { redirectTo: string; isSignupFlow?: boolean; href: string }) {
64-
const client = await getAuthClient();
59+
const client = getAuthClient();
6560
return client.login(args);
6661
},
6762
async handleSigninRedirect(href: string) {
68-
const client = await getAuthClient();
63+
const client = getAuthClient();
6964
return client.handleSigninRedirect(href);
7065
},
7166
async logout() {
72-
const client = await getAuthClient();
67+
const client = getAuthClient();
7368
return client.logout();
7469
},
7570
async getTokenOrRedirect(skipRedirect?: boolean) {
76-
const client = await getAuthClient();
71+
const client = getAuthClient();
7772
return client.getTokenOrRedirect(skipRedirect);
7873
},
7974
async loginWithPassword(args: { email: string; password: string }) {
80-
const client = await getAuthClient();
75+
const client = getAuthClient();
8176
return client.loginWithPassword(args);
8277
},
8378
async loginWithOAuth(args: { provider: OAuthProvider; redirectTo: string }) {
84-
const client = await getAuthClient();
79+
const client = getAuthClient();
8580
return client.loginWithOAuth(args);
8681
},
8782
async signupWithPassword(args: { email: string; password: string; firstName: string; lastName: string }) {
88-
const client = await getAuthClient();
83+
const client = getAuthClient();
8984
return client.signupWithPassword(args);
9085
},
9186
async verifyEmail(args: { pendingAuthenticationToken: string; code: string }) {
92-
const client = await getAuthClient();
87+
const client = getAuthClient();
9388
return client.verifyEmail(args);
9489
},
9590
async sendResetPassword(args: { email: string }) {
96-
const client = await getAuthClient();
91+
const client = getAuthClient();
9792
return client.sendResetPassword(args);
9893
},
9994
async resetPassword(args: { token: string; password: string }) {
100-
const client = await getAuthClient();
95+
const client = getAuthClient();
10196
return client.resetPassword(args);
10297
},
10398
async sendMagicAuthCode(args: { email: string }) {
104-
const client = await getAuthClient();
99+
const client = getAuthClient();
105100
return client.sendMagicAuthCode(args);
106101
},
107102
async authenticateWithMagicCode(args: { email: string; code: string }) {
108-
const client = await getAuthClient();
103+
const client = getAuthClient();
109104
return client.authenticateWithMagicCode(args);
110105
},
111106
};

quadratic-client/src/shared/hooks/useRemoveInitialLoadingUI.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ export function useRemoveInitialLoadingUI() {
1414
if (startTime) {
1515
startupTimer.start('firstRender', Number(startTime));
1616
startupTimer.end('firstRender');
17-
}
18-
19-
const timers = startupTimer.show();
20-
if (timers) {
21-
trackEvent('[Loading].complete', {
22-
route: window.location.pathname + window.location.search,
23-
...timers,
24-
});
17+
const timers = startupTimer.show();
18+
if (timers) {
19+
trackEvent('[Loading].complete', {
20+
route: window.location.pathname + window.location.search,
21+
...timers,
22+
});
23+
}
2524
}
2625
}, []);
2726
return null;

0 commit comments

Comments
 (0)