diff --git a/frontend/src/hooks/documents/useDocumentCorrespondentActions.ts b/frontend/src/hooks/documents/useDocumentCorrespondentActions.ts index 28ba59c..65c57a4 100644 --- a/frontend/src/hooks/documents/useDocumentCorrespondentActions.ts +++ b/frontend/src/hooks/documents/useDocumentCorrespondentActions.ts @@ -1,5 +1,5 @@ import { useCallback, useMemo } from 'react'; -import { isPlainObject, isStringValue } from '../../utils/typeGuards'; +import { isPlainObject } from '../../utils/typeGuards'; type ApiClient = { post: (path: string, body?: unknown) => Promise<{ data: unknown }>; @@ -127,7 +127,7 @@ const useDocumentCorrespondentActions = ({ if (isPlainObject(option) && 'id' in option) { return option as CorrespondentOption; } - if (isStringValue(option)) { + if (typeof option === 'string') { const trimmed = option.trim(); if (trimmed) { return { id: null, name: trimmed }; diff --git a/frontend/src/utils/typeGuards.ts b/frontend/src/utils/typeGuards.ts index ca9260f..40d70a5 100644 --- a/frontend/src/utils/typeGuards.ts +++ b/frontend/src/utils/typeGuards.ts @@ -3,5 +3,4 @@ const objectToString = Object.prototype.toString; export const isPlainObject = (value: unknown): value is Record => value !== null && !Array.isArray(value) && Object(value) === value; -export const isStringValue = (value: unknown): value is string => - objectToString.call(value) === '[object String]'; + diff --git a/frontend/src/utils/webauthn.ts b/frontend/src/utils/webauthn.ts index 555cff8..f2aba51 100644 --- a/frontend/src/utils/webauthn.ts +++ b/frontend/src/utils/webauthn.ts @@ -26,8 +26,6 @@ type AuthenticationCredential = PublicKeyCredential & { response: AuthenticatorAssertionResponse; }; -import { isStringValue } from './typeGuards'; - const base64urlToBase64 = (value: string = ''): string => { const normalized = value.replace(/-/g, '+').replace(/_/g, '/'); const padding = normalized.length % 4; @@ -103,14 +101,14 @@ export const preparePublicKeyCreationOptions = ( const publicKey: PublicKeyCredentialCreationOptions = { ...challengeResponse.publicKey }; - if (publicKey.challenge && isStringValue(publicKey.challenge)) { + if (publicKey.challenge && typeof publicKey.challenge === 'string') { publicKey.challenge = base64urlToBufferSource(publicKey.challenge); } if (publicKey.user?.id) { publicKey.user = { ...publicKey.user, - id: isStringValue(publicKey.user.id) + id: typeof publicKey.user.id === 'string' ? base64urlToBufferSource(publicKey.user.id) : publicKey.user.id, }; @@ -119,7 +117,7 @@ export const preparePublicKeyCreationOptions = ( if (Array.isArray(publicKey.excludeCredentials)) { publicKey.excludeCredentials = publicKey.excludeCredentials.map((descriptor) => ({ ...descriptor, - id: isStringValue(descriptor.id) + id: typeof descriptor.id === 'string' ? base64urlToBufferSource(descriptor.id) : descriptor.id, })); @@ -141,14 +139,14 @@ export const preparePublicKeyRequestOptions = ( const publicKey: PublicKeyCredentialRequestOptions = { ...challengeResponse.publicKey }; - if (publicKey.challenge && isStringValue(publicKey.challenge)) { + if (publicKey.challenge && typeof publicKey.challenge === 'string') { publicKey.challenge = base64urlToBufferSource(publicKey.challenge); } if (Array.isArray(publicKey.allowCredentials)) { publicKey.allowCredentials = publicKey.allowCredentials.map((descriptor) => ({ ...descriptor, - id: isStringValue(descriptor.id) + id: typeof descriptor.id === 'string' ? base64urlToBufferSource(descriptor.id) : descriptor.id, }));