Skip to content

Commit 595829f

Browse files
committed
Forward hasItem options; change iOS auth errors
Stop normalizing storage options in useHasSecret and pass the provided SensitiveInfoOptions straight to hasItem. Update unit tests to assert the forwarded options and the native getAllItems call signature. On iOS, remove the early-return that suppressed errSecInteractionNotAllowed/errSecAuthFailed when allowAuthentication was false so those statuses now raise the runtime error instead of returning nil.
1 parent 83dddbe commit 595829f

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

ios/HybridSensitiveInfo.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ public final class HybridSensitiveInfo: HybridSensitiveInfoSpec {
407407
case errSecItemNotFound:
408408
return nil
409409
case errSecInteractionNotAllowed, errSecAuthFailed:
410-
if !allowAuthentication { return nil }
411410
throw runtimeError(for: status, operation: "fetch")
412411
default:
413412
throw runtimeError(for: status, operation: "fetch")

src/__tests__/core.storage.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ describe('core/storage', () => {
288288
authenticationPrompt: prompt,
289289
})
290290
expect(normalizePromptedReadOptions).not.toHaveBeenCalled()
291+
expect(nativeHandle.getAllItems).toHaveBeenCalledWith({
292+
includeValues: false,
293+
service: 'normalized',
294+
} as SensitiveInfoEnumerateRequest)
291295
})
292296

293297
it('clears a service via native call', async () => {

src/__tests__/hooks.useHasSecret.test.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,25 @@ describe('useHasSecret', () => {
3434
expect(mockedHasItem).toHaveBeenCalledWith('token', { service: 'auth' })
3535
})
3636

37-
it('keeps existence checks silent when prompt options are provided', async () => {
37+
it('forwards existence options to the silent hasItem boundary', async () => {
3838
mockedHasItem.mockResolvedValueOnce(true)
39+
const options = {
40+
service: 'auth',
41+
accessControl: 'biometryCurrentSet' as const,
42+
authenticationPrompt: { title: 'Unlock' },
43+
}
3944

4045
renderHook(
4146
({ opts }: { opts: Parameters<typeof useHasSecret>[1] }) =>
4247
useHasSecret('token', opts),
4348
{
44-
initialProps: {
45-
opts: {
46-
service: 'auth',
47-
accessControl: 'biometryCurrentSet',
48-
authenticationPrompt: { title: 'Unlock' },
49-
},
50-
},
49+
initialProps: { opts: options },
5150
}
5251
)
5352

5453
await waitFor(() => expect(mockedHasItem).toHaveBeenCalled())
5554

56-
expect(mockedHasItem).toHaveBeenCalledWith('token', { service: 'auth' })
55+
expect(mockedHasItem).toHaveBeenCalledWith('token', options)
5756
})
5857

5958
it('skips querying when requested', async () => {

src/hooks/useHasSecret.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useCallback } from 'react'
22
import { hasItem } from '../core/storage'
3-
import { normalizeStorageScopeOptions } from '../internal/options'
43
import type { SensitiveInfoOptions } from '../sensitive-info.nitro'
54
import type { AsyncState } from './types'
65
import useAsyncQuery from './useAsyncQuery'
@@ -44,8 +43,7 @@ export function useHasSecret(
4443
options?: UseHasSecretOptions
4544
): UseHasSecretResult {
4645
const runner = useCallback(
47-
(request: SensitiveInfoOptions) =>
48-
hasItem(key, normalizeStorageScopeOptions(request)),
46+
(request: SensitiveInfoOptions) => hasItem(key, request),
4947
[key]
5048
)
5149
return useAsyncQuery<boolean, UseHasSecretOptions>(

0 commit comments

Comments
 (0)