@@ -19,8 +19,14 @@ import { Alert, Platform } from "react-native";
1919import Config from "react-native-config" ;
2020import * as RNLocalize from "react-native-localize" ;
2121import RNRestart from "react-native-restart" ;
22- import type { SensitiveInfoError } from "react-native-sensitive-info" ;
23- import RNSInfo , { ErrorCode , isSensitiveInfoError } from "react-native-sensitive-info" ;
22+ import {
23+ deleteItem ,
24+ ErrorCode ,
25+ getItem ,
26+ hasItem ,
27+ SensitiveInfoError ,
28+ setItem ,
29+ } from "react-native-sensitive-info" ;
2430import Realm , { UpdateMode } from "realm" ;
2531import realmConfig from "realmModels/index" ;
2632import changeLanguage from "sharedHelpers/changeLanguage" ;
@@ -58,7 +64,7 @@ interface AuthCache {
5864}
5965
6066/**
61- * Cache for isLoggedIn, to avoid making too many calls to RNSInfo. getItem
67+ * Cache for isLoggedIn, to avoid making too many calls to getItem
6268 */
6369const authCache : AuthCache = {
6470 isLoggedIn : null ,
@@ -88,17 +94,16 @@ const clearAuthCache = ( ): void => {
8894async function getSensitiveItem (
8995 key : string ,
9096 options = {
91- keychainService : "app" as const ,
97+ service : "app" as const ,
9298 } ,
9399) {
94100 let exists ;
95101 try {
96- exists = await RNSInfo . hasItem ( key , options ) ;
102+ exists = await hasItem ( key , options ) ;
97103 } catch ( e ) {
98- if ( isSensitiveInfoError ( e ) ) {
99- const hasItemError = e as SensitiveInfoError ;
104+ if ( e instanceof SensitiveInfoError ) {
100105 localLogger . info (
101- `RNSInfo. hasItem error for ${ key } : ${ hasItemError . message } ` ,
106+ `hasItem error for ${ key } : ${ e . message } ` ,
102107 ) ;
103108 }
104109 throw e ;
@@ -108,20 +113,18 @@ async function getSensitiveItem(
108113 }
109114
110115 try {
111- return await RNSInfo . getItem ( key , options ) ;
116+ const item = await getItem ( key , options ) ;
117+ return item ?. value ?? null ;
112118 } catch ( e ) {
113- if ( isSensitiveInfoError ( e ) ) {
114- const getItemError = e as SensitiveInfoError ;
115- if ( isDebugModeSync ( ) ) {
116- switch ( getItemError . code ) {
117- case ErrorCode . NOT_FOUND :
118- // Value doesn't exist
119- localLogger . info ( `RNSInfo.getItem not available for ${ key } ` ) ;
120- break ;
121- default :
122- localLogger . info ( `RNSInfo.getItem unknown error for ${ key } : ${ getItemError . message } ` ) ;
123- break ;
124- }
119+ if ( e instanceof SensitiveInfoError && isDebugModeSync ( ) ) {
120+ switch ( e . code ) {
121+ case ErrorCode . NotFound :
122+ // Value doesn't exist
123+ localLogger . info ( `getItem not available for ${ key } ` ) ;
124+ break ;
125+ default :
126+ localLogger . info ( `getItem unknown error for ${ key } : ${ e . message } ` ) ;
127+ break ;
125128 }
126129 }
127130 throw e ;
@@ -132,22 +135,19 @@ async function setSensitiveItem( key: string, value: string, options = {} ) {
132135 const actualOptions = {
133136 // I put the key as overridable by actual options propped in,
134137 // in case someone wants to build a separate slice at one point.
135- keychainService : "app" as const ,
138+ service : "app" as const ,
136139 ...options ,
137140 accessControl : "none" as const ,
138141 } ;
139142 try {
140- const result = await RNSInfo . setItem ( key , value , actualOptions ) ;
143+ const result = await setItem ( key , value , actualOptions ) ;
141144 clearAuthCache ( ) ;
142145 return result ;
143146 } catch ( e ) {
144- if ( isSensitiveInfoError ( e ) ) {
145- const setItemError = e as SensitiveInfoError ;
146- if ( isDebugModeSync ( ) ) {
147- localLogger . info (
148- `RNSInfo.setItem error for ${ key } , ${ setItemError . code } ${ setItemError . message } ` ,
149- ) ;
150- }
147+ if ( e instanceof SensitiveInfoError && isDebugModeSync ( ) ) {
148+ localLogger . info (
149+ `setItem error for ${ key } , ${ e . code } ${ e . message } ` ,
150+ ) ;
151151 }
152152 throw e ;
153153 }
@@ -156,21 +156,18 @@ async function setSensitiveItem( key: string, value: string, options = {} ) {
156156async function deleteSensitiveItem (
157157 key : string ,
158158 options = {
159- keychainService : "app" as const ,
159+ service : "app" as const ,
160160 } ,
161161) {
162162 try {
163- const result = await RNSInfo . deleteItem ( key , options ) ;
163+ const result = await deleteItem ( key , options ) ;
164164 clearAuthCache ( ) ;
165165 return result ;
166166 } catch ( e ) {
167- if ( isSensitiveInfoError ( e ) ) {
168- const deleteItemError = e as SensitiveInfoError ;
169- if ( isDebugModeSync ( ) ) {
170- localLogger . info (
171- `RNSInfo.deleteItem error for ${ key } , ${ deleteItemError . code } ${ deleteItemError . message } ` ,
172- ) ;
173- }
167+ if ( e instanceof SensitiveInfoError && isDebugModeSync ( ) ) {
168+ localLogger . info (
169+ `deleteItem error for ${ key } , ${ e . code } ${ e . message } ` ,
170+ ) ;
174171 }
175172 throw e ;
176173 }
0 commit comments