Skip to content

Commit 8f33cfe

Browse files
committed
refactor(auth): simplify Google connection logic by removing session linking option
- Removed the `shouldTryLinkingWithSessionUser` option from the Google authentication hooks and related tests to streamline the connection process. - Updated the `initSupertokens` middleware to automatically disable account linking for new accounts without email. - Adjusted tests for `useConnectGoogle` to reflect the removal of session linking logic, ensuring accurate behavior during Google connection scenarios.
1 parent 2777040 commit 8f33cfe

5 files changed

Lines changed: 3 additions & 25 deletions

File tree

packages/backend/src/common/middleware/supertokens.middleware.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,8 @@ export const initSupertokens = () => {
5454
framework: "express",
5555
recipeList: [
5656
AccountLinking.init({
57-
shouldDoAutomaticAccountLinking: async (newAccountInfo) => {
58-
if (!newAccountInfo.email) {
59-
return { shouldAutomaticallyLink: false };
60-
}
61-
62-
return {
63-
shouldAutomaticallyLink: true,
64-
shouldRequireVerification: true,
65-
};
57+
shouldDoAutomaticAccountLinking: () => {
58+
return Promise.resolve({ shouldAutomaticallyLink: false });
6659
},
6760
}),
6861
// see added endpoints

packages/web/src/auth/hooks/oauth/useConnectGoogle.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ describe("useConnectGoogle", () => {
7070

7171
expect(mockUseGoogleAuth).toHaveBeenCalledWith({
7272
prompt: "consent",
73-
shouldTryLinkingWithSessionUser: true,
7473
});
7574
expect(result.current.commandAction.label).toBe(
7675
"Checking Google Calendar…",
@@ -99,7 +98,6 @@ describe("useConnectGoogle", () => {
9998

10099
expect(mockUseGoogleAuth).toHaveBeenCalledWith({
101100
prompt: "consent",
102-
shouldTryLinkingWithSessionUser: true,
103101
});
104102
expect(result.current.commandAction.label).toBe("Connect Google Calendar");
105103
expect(result.current.commandAction.isDisabled).toBe(false);
@@ -126,7 +124,6 @@ describe("useConnectGoogle", () => {
126124

127125
expect(mockUseGoogleAuth).toHaveBeenCalledWith({
128126
prompt: "consent",
129-
shouldTryLinkingWithSessionUser: true,
130127
});
131128
expect(result.current.commandAction.label).toBe(
132129
"Google Calendar Connected",
@@ -154,7 +151,6 @@ describe("useConnectGoogle", () => {
154151

155152
expect(mockUseGoogleAuth).toHaveBeenCalledWith({
156153
prompt: "consent",
157-
shouldTryLinkingWithSessionUser: true,
158154
});
159155
expect(result.current.commandAction.label).toBe(
160156
"Reconnect Google Calendar",
@@ -185,7 +181,6 @@ describe("useConnectGoogle", () => {
185181

186182
expect(mockUseGoogleAuth).toHaveBeenCalledWith({
187183
prompt: "consent",
188-
shouldTryLinkingWithSessionUser: true,
189184
});
190185
expect(result.current.commandAction.label).toBe("Syncing Google Calendar…");
191186
expect(result.current.commandAction.isDisabled).toBe(true);
@@ -211,7 +206,6 @@ describe("useConnectGoogle", () => {
211206

212207
expect(mockUseGoogleAuth).toHaveBeenCalledWith({
213208
prompt: "consent",
214-
shouldTryLinkingWithSessionUser: true,
215209
});
216210
expect(result.current.commandAction.label).toBe("Repair Google Calendar");
217211
expect(result.current.commandAction.isDisabled).toBe(false);
@@ -257,7 +251,6 @@ describe("useConnectGoogle", () => {
257251

258252
expect(mockUseGoogleAuth).toHaveBeenCalledWith({
259253
prompt: "consent",
260-
shouldTryLinkingWithSessionUser: true,
261254
});
262255
expect(result.current.commandAction.label).toBe("Connect Google Calendar");
263256
expect(result.current.commandAction.isDisabled).toBe(false);
@@ -282,7 +275,6 @@ describe("useConnectGoogle", () => {
282275

283276
expect(mockUseGoogleAuth).toHaveBeenCalledWith({
284277
prompt: "consent",
285-
shouldTryLinkingWithSessionUser: true,
286278
});
287279
expect(result.current.commandAction.label).toBe(
288280
"Reconnect Google Calendar",
@@ -309,7 +301,6 @@ describe("useConnectGoogle", () => {
309301

310302
expect(mockUseGoogleAuth).toHaveBeenCalledWith({
311303
prompt: "consent",
312-
shouldTryLinkingWithSessionUser: true,
313304
});
314305
expect(result.current.commandAction.label).toBe("Connect Google Calendar");
315306
expect(result.current.sidebarStatus.icon).toBe("CloudArrowUpIcon");

packages/web/src/auth/hooks/oauth/useConnectGoogle.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useCallback } from "react";
22
import { type GoogleConnectionState } from "@core/types/user.types";
33
import { useGoogleAuth } from "@web/auth/hooks/oauth/useGoogleAuth";
4-
import { useSession } from "@web/auth/hooks/session/useSession";
54
import { hasUserEverAuthenticated } from "@web/auth/state/auth.state.util";
65
import { SyncApi } from "@web/common/apis/sync.api";
76
import {
@@ -143,15 +142,13 @@ const getGoogleUiConfig = (
143142

144143
export const useConnectGoogle = () => {
145144
const dispatch = useAppDispatch();
146-
const { authenticated } = useSession();
147145
const connectionState = useAppSelector(
148146
selectGoogleConnectionState as (state: RootState) => GoogleConnectionState,
149147
);
150148
const userMetadataStatus = useAppSelector(
151149
selectUserMetadataStatus as (state: RootState) => UserMetadataStatus,
152150
);
153151
const { login } = useGoogleAuth({
154-
shouldTryLinkingWithSessionUser: authenticated,
155152
prompt: "consent",
156153
});
157154

packages/web/src/auth/hooks/oauth/useGoogleAuth.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ const resetAuthState = (dispatch: AppDispatch) => {
3636

3737
export function useGoogleAuth(
3838
options: {
39-
shouldTryLinkingWithSessionUser?: boolean;
4039
prompt?: "consent" | "none" | "select_account";
4140
} = {},
4241
) {
4342
const dispatch = useAppDispatch();
4443
const completeAuthentication = useCompleteAuthentication();
45-
const { shouldTryLinkingWithSessionUser, prompt } = options;
44+
const { prompt } = options;
4645

4746
const googleLogin = useGoogleAuthWithOverlay({
4847
prompt,
@@ -55,7 +54,6 @@ export function useGoogleAuth(
5554
try {
5655
const authPayload: SignInUpInput = {
5756
...data,
58-
shouldTryLinkingWithSessionUser,
5957
};
6058
const authResult = await authenticate(authPayload);
6159
if (!authResult.success) {

packages/web/src/components/oauth/ouath.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { type CodeResponse } from "@react-oauth/google";
33
export interface SignInUpInput {
44
thirdPartyId: string;
55
clientType: "web";
6-
shouldTryLinkingWithSessionUser?: boolean;
76
redirectURIInfo: {
87
redirectURIOnProviderDashboard: string;
98
redirectURIQueryParams: Omit<

0 commit comments

Comments
 (0)