Skip to content
Closed
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
1 change: 0 additions & 1 deletion __tests__/components/auth/SeizeConnectContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jest.mock('viem', () => ({

// Mock auth utils
jest.mock('../../../services/auth/auth.utils', () => ({
migrateCookiesToLocalStorage: jest.fn(),
getWalletAddress: jest.fn(() => null),
removeAuthJwt: jest.fn(),
}));
Expand Down
2 changes: 0 additions & 2 deletions __tests__/components/header/share/HeaderShare.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,12 @@ const mockAuthUtils = {
getRefreshToken: jest.fn(() => null),
getWalletAddress: jest.fn(() => null),
getWalletRole: jest.fn(() => null),
migrateCookiesToLocalStorage: jest.fn(),
removeAuthJwt: jest.fn()
};

require("../../../../services/auth/auth.utils").getRefreshToken = mockAuthUtils.getRefreshToken;
require("../../../../services/auth/auth.utils").getWalletAddress = mockAuthUtils.getWalletAddress;
require("../../../../services/auth/auth.utils").getWalletRole = mockAuthUtils.getWalletRole;
require("../../../../services/auth/auth.utils").migrateCookiesToLocalStorage = mockAuthUtils.migrateCookiesToLocalStorage;
require("../../../../services/auth/auth.utils").removeAuthJwt = mockAuthUtils.removeAuthJwt;

const mockUseCapacitor = useCapacitor as jest.MockedFunction<
Expand Down
16 changes: 1 addition & 15 deletions __tests__/services/auth.utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setAuthJwt, getAuthJwt, getStagingAuth, removeAuthJwt, migrateCookiesToLocalStorage, getWalletAddress } from '../../services/auth/auth.utils';
import { setAuthJwt, getAuthJwt, getStagingAuth, removeAuthJwt, getWalletAddress } from '../../services/auth/auth.utils';
import Cookies from 'js-cookie';
import { safeLocalStorage } from '../../helpers/safeLocalStorage';
import { jwtDecode } from 'jwt-decode';
Expand Down Expand Up @@ -41,20 +41,6 @@ describe('auth.utils', () => {
expect(getStagingAuth()).toBe('e');
});

it('migrateCookiesToLocalStorage moves and removes cookies', () => {
(Cookies.get as jest.Mock)
.mockReturnValueOnce('addr')
.mockReturnValueOnce('refresh')
.mockReturnValueOnce('role');
migrateCookiesToLocalStorage();
expect(safeLocalStorage.setItem).toHaveBeenCalledWith('6529-wallet-address', 'addr');
expect(Cookies.remove).toHaveBeenCalledWith('wallet-address');
expect(safeLocalStorage.setItem).toHaveBeenCalledWith('6529-wallet-refresh-token', 'refresh');
expect(Cookies.remove).toHaveBeenCalledWith('wallet-refresh-token');
expect(safeLocalStorage.setItem).toHaveBeenCalledWith('6529-wallet-role', 'role');
expect(Cookies.remove).toHaveBeenCalledWith('wallet-role');
});

it('getWalletAddress respects dev mode and storage', () => {
process.env.USE_DEV_AUTH = 'true';
process.env.DEV_MODE_WALLET_ADDRESS = 'devaddr';
Expand Down
10 changes: 1 addition & 9 deletions components/auth/SeizeConnectContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import React, {
useRef,
} from "react";

import {
migrateCookiesToLocalStorage,
getWalletAddress,
removeAuthJwt,
} from "../../services/auth/auth.utils";
import { getWalletAddress, removeAuthJwt } from "../../services/auth/auth.utils";
import { WalletInitializationError } from "../../src/errors/wallet";
import { useAppKit, useAppKitAccount, useAppKitState, useDisconnect } from "@reown/appkit/react";
import { isAddress, getAddress } from "viem";
Expand Down Expand Up @@ -342,10 +338,6 @@ export const SeizeConnectProvider: React.FC<{ children: React.ReactNode }> = ({
} = useConsolidatedWalletState();
const debounceTimeoutRef = useRef<NodeJS.Timeout | null>(null);

useEffect(() => {
migrateCookiesToLocalStorage();
}, []);

useEffect(() => {
// Wait for initialization to complete before processing account changes
if (!isInitialized) {
Expand Down
28 changes: 0 additions & 28 deletions services/auth/auth.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import { API_AUTH_COOKIE } from "../../constants";

export const WALLET_AUTH_COOKIE = "wallet-auth";

// TODO: remove these cookies once migration is complete
const WALLET_ADDRESS_COOKIE = "wallet-address";
const WALLET_REFRESH_TOKEN_COOKIE = "wallet-refresh-token";
const WALLET_ROLE_COOKIE = "wallet-role";

const WALLET_ADDRESS_STORAGE_KEY = "6529-wallet-address";
const WALLET_REFRESH_TOKEN_STORAGE_KEY = "6529-wallet-refresh-token";
const WALLET_ROLE_STORAGE_KEY = "6529-wallet-role";
Expand All @@ -26,29 +21,6 @@ const getJwtExpiration = (jwt: string): number => {
return decodedJwt.exp;
};

// TODO: remove these cookies once migration is complete
export const migrateCookiesToLocalStorage = () => {
const walletAddress = Cookies.get(WALLET_ADDRESS_COOKIE);
const walletRefreshToken = Cookies.get(WALLET_REFRESH_TOKEN_COOKIE);
const walletRole = Cookies.get(WALLET_ROLE_COOKIE);

if (walletAddress) {
safeLocalStorage.setItem(WALLET_ADDRESS_STORAGE_KEY, walletAddress);
Cookies.remove(WALLET_ADDRESS_COOKIE);
}
if (walletRefreshToken) {
safeLocalStorage.setItem(
WALLET_REFRESH_TOKEN_STORAGE_KEY,
walletRefreshToken
);
Cookies.remove(WALLET_REFRESH_TOKEN_COOKIE);
}
if (walletRole) {
safeLocalStorage.setItem(WALLET_ROLE_STORAGE_KEY, walletRole);
Cookies.remove(WALLET_ROLE_COOKIE);
}
};

export const setAuthJwt = (
address: string,
jwt: string,
Expand Down