diff --git a/packages/mobile/src/screens/oauth-screen/hooks/useParsedParams.ts b/packages/mobile/src/screens/oauth-screen/hooks/useParsedParams.ts index 57987ebacb0..29fa5100a5f 100644 --- a/packages/mobile/src/screens/oauth-screen/hooks/useParsedParams.ts +++ b/packages/mobile/src/screens/oauth-screen/hooks/useParsedParams.ts @@ -26,12 +26,16 @@ export const useParsedParams = (search: string): ParsedParams => { } = queryString.parse(search) const scope = collapseScope(rawScope) - const apiKey = - typeof api_key === 'string' - ? api_key - : typeof client_id === 'string' - ? client_id - : null + const apiKey = (() => { + const raw = + typeof api_key === 'string' + ? api_key + : typeof client_id === 'string' + ? client_id + : null + if (raw?.toLowerCase().startsWith('0x')) return raw.slice(2) + return raw + })() const redirectUriStr = typeof redirectUri === 'string' ? redirectUri : null let error: string | null = null diff --git a/packages/mobile/src/screens/oauth-screen/utils.ts b/packages/mobile/src/screens/oauth-screen/utils.ts index 439a0f59725..4cd12ef04ed 100644 --- a/packages/mobile/src/screens/oauth-screen/utils.ts +++ b/packages/mobile/src/screens/oauth-screen/utils.ts @@ -7,8 +7,9 @@ import { audiusSdk } from 'app/services/sdk/audius-sdk' // ─── URL / key validation ───────────────────────────────────────────────────── export const isValidApiKey = (key: string) => { - if (key.length !== 40) return false - return /^[0-9a-fA-F]+$/.test(key) + const normalized = key.toLowerCase().startsWith('0x') ? key.slice(2) : key + if (normalized.length !== 40) return false + return /^[0-9a-fA-F]+$/.test(normalized) } export const getIsRedirectValid = ( diff --git a/packages/web/src/pages/oauth-login-page/hooks.ts b/packages/web/src/pages/oauth-login-page/hooks.ts index 9b2698f4664..ab088560e3e 100644 --- a/packages/web/src/pages/oauth-login-page/hooks.ts +++ b/packages/web/src/pages/oauth-login-page/hooks.ts @@ -75,12 +75,16 @@ const useParsedQueryParams = () => { const scope = collapseScopes(rawScope) - const apiKey = - typeof api_key === 'string' - ? api_key - : typeof client_id === 'string' - ? client_id - : undefined + const apiKey = (() => { + const raw = + typeof api_key === 'string' + ? api_key + : typeof client_id === 'string' + ? client_id + : undefined + if (raw?.toLowerCase().startsWith('0x')) return raw.slice(2) + return raw + })() const parsedRedirectUri = useMemo<'postmessage' | URL | null>(() => { if (redirectUri && typeof redirectUri === 'string') { diff --git a/packages/web/src/pages/oauth-login-page/utils.ts b/packages/web/src/pages/oauth-login-page/utils.ts index ed2b986c1d3..ef40272913d 100644 --- a/packages/web/src/pages/oauth-login-page/utils.ts +++ b/packages/web/src/pages/oauth-login-page/utils.ts @@ -41,11 +41,12 @@ export const getIsRedirectValid = ({ export const isValidApiKey = (key: string | string[]) => { if (Array.isArray(key)) return false - if (key.length !== 40) { + const normalized = key.toLowerCase().startsWith('0x') ? key.slice(2) : key + if (normalized.length !== 40) { return false } const hexadecimalRegex = /^[0-9a-fA-F]+$/ - return hexadecimalRegex.test(key) + return hexadecimalRegex.test(normalized) } const getFormattedAppAddress = ({