Skip to content

Commit 1e403d7

Browse files
MOB-1679 #comment save pin registration state
1 parent 7190dc4 commit 1e403d7

5 files changed

Lines changed: 29 additions & 24 deletions

File tree

android/src/main/java/com/tsauthentication/TsAuthenticationModule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public void error(TSNativeBiometricsApprovalError error) {
371371

372372
@ReactMethod
373373
@NonNull
374-
public void registerPin(String username, String pinCode, Promise promise) {
374+
public void registerPinCode(String username, String pinCode, Promise promise) {
375375
if (reactContext.getCurrentActivity() != null) {
376376

377377
AppCompatActivity appCompatActivity = getAppCompatActivity();
@@ -413,7 +413,7 @@ public void commitPinRegistration(String contextIdentifier, Promise promise) {
413413
TSPinCodeRegistrationContext context =
414414
(TSPinCodeRegistrationContext) getContextWithIdentifier(contextIdentifier);
415415

416-
if (context != null) {
416+
if (context == null) {
417417
promise.reject("result", "PIN Registration Context not found for the context identifier provided");
418418
} else {
419419
removeContextWithIdentifier(contextIdentifier);
@@ -424,7 +424,7 @@ public void commitPinRegistration(String contextIdentifier, Promise promise) {
424424

425425
@ReactMethod
426426
@NonNull
427-
public void onAuthenticatePinCode(String username, String pinCode, String challenge, Promise promise) {
427+
public void authenticatePinCode(String username, String pinCode, String challenge, Promise promise) {
428428
if (reactContext.getCurrentActivity() != null) {
429429

430430
AppCompatActivity appCompatActivity = getAppCompatActivity();

example/src/App.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@ export default class App extends React.Component<any, State> {
299299

300300
// PIN Code Registration / Authentication
301301

302-
private onRegisterPINCode = async (rawUsername: string, pinCode: string): Promise<void> => {
302+
private onRegisterPINCode = async (rawUsername: string, pinCode: string): Promise<boolean> => {
303303
if (rawUsername === '' || pinCode === '') {
304304
this.setState({ errorMessage: 'Please enter a username and PIN code' });
305-
return;
305+
return false;
306306
}
307307
this.setState({ loading: true });
308308
const username = rawUsername.toLowerCase();
@@ -314,26 +314,30 @@ export default class App extends React.Component<any, State> {
314314
await TSAuthenticationSDKModule.commitPinRegistration(result.contextIdentifier);
315315
localUserStore.setHasRegisteredPIN(username, true);
316316
Alert.alert("PIN Code Registration", "PIN code registered successfully");
317+
return true;
317318
} catch (error: any) {
318319
this.setState({ errorMessage: `${error}` });
320+
return false;
319321
} finally {
320322
this.setState({ loading: false });
321323
}
322324
}
323325

324-
private onAuthenticatePinCode = async (username: string, pinCode: string): Promise<void> => {
326+
private onAuthenticatePinCode = async (username: string, pinCode: string): Promise<boolean> => {
325327
if (username === '' || pinCode === '') {
326328
this.setState({ errorMessage: 'Please enter a username and PIN code' });
327-
return;
329+
return false;
328330
}
329331
this.setState({ loading: true });
330332

331333
const challenge = this.randomString();
332334
try {
333335
const result = await TSAuthenticationSDKModule.authenticatePinCode(username, pinCode, challenge);
334336
Alert.alert("Authentication result: ", JSON.stringify(result));
337+
return true;
335338
} catch (error: any) {
336339
this.setState({ errorMessage: `${error}` });
340+
return false;
337341
} finally {
338342
this.setState({ loading: false });
339343
}

example/src/config.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
// export default {
2-
// clientId: "REPLACE_WITH_CLIENT_ID",
3-
// domain: "REPLACE_WITH_DOMAIN",
4-
// secret: "REPLACE_WITH_SECRET", // Important! This is just for demo purposes. Never store your secret in the client side.
5-
// baseUrl: "https://api.transmitsecurity.io", // eu = "api.eu.transmitsecurity.io" ca = "api.ca.transmitsecurity.io"
6-
// }
7-
8-
91
export default {
10-
clientId: "4q2wb5f3z063dqjq1ixilwbm4gx57yyw",
11-
domain: "webcredentials:shopcart.userid-stg.io",
12-
secret: "108f4506-0b06-4557-b807-41e09979ceee", // Important! This is just for demo purposes. Never store your secret in the client side.
2+
clientId: "REPLACE_WITH_CLIENT_ID",
3+
domain: "REPLACE_WITH_DOMAIN",
4+
secret: "REPLACE_WITH_SECRET", // Important! This is just for demo purposes. Never store your secret in the client side.
135
baseUrl: "https://api.transmitsecurity.io", // eu = "api.eu.transmitsecurity.io" ca = "api.ca.transmitsecurity.io"
14-
}
6+
}

example/src/home.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export type Props = {
1616
onApprovalWebAuthn: (username: string, approvalData: { [key: string]: string; }) => void;
1717
onApprovalWebAuthnWithData: (rawAuthenticationData: TSAuthenticationSDK.WebAuthnAuthenticationData ) => void;
1818
onApprovalNativeBiometrics: (username: string) => void;
19-
onRegisterPINCode: (username: string, pinCode: string) => void;
20-
onAuthenticatePinCode: (username: string, pinCode: string) => void;
19+
onRegisterPINCode: (username: string, pinCode: string) => Promise<boolean>;
20+
onAuthenticatePinCode: (username: string, pinCode: string) => Promise<boolean>;
2121
errorMessage: string;
2222
};
2323

@@ -285,7 +285,7 @@ export default class HomeScreen extends React.Component<Props, State> {
285285
this.setState({ showPinDialog: false, pinInput: '', pinError: '' });
286286
}
287287

288-
private handlePinDialogDone = () => {
288+
private handlePinDialogDone = async () => {
289289
const { pinInput, username } = this.state;
290290
if (!pinInput || pinInput.length !== 4 || !username || username.trim() === '') {
291291
this.setState({ pinError: 'Please enter a User ID and a 4-digit PIN.' });
@@ -294,7 +294,10 @@ export default class HomeScreen extends React.Component<Props, State> {
294294
this.setState({ showPinDialog: false, pinError: '' });
295295

296296
if (this.state.pinAuthenticatorMode === PinAuthenticatorMode.REGISTER) {
297-
this.props.onRegisterPINCode(this.state.username, pinInput);
297+
const results = await this.props.onRegisterPINCode(this.state.username, pinInput);
298+
if (results) {
299+
this.setState({ hasRegisteredPIN: true });
300+
}
298301
} else {
299302
this.props.onAuthenticatePinCode(this.state.username, pinInput);
300303
}

example/src/utils/local-user-store.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class LocalUserStore {
3535
}
3636

3737
public hasRegisteredPIN = (userID: string): boolean => {
38+
console.log('Checking PIN status for user:', userID);
39+
console.log(this.store.pinStatus)
3840
return !!this.store.pinStatus[userID];
3941
}
4042

@@ -55,7 +57,11 @@ class LocalUserStore {
5557
private updateUserStore = async (): Promise<void> => {
5658
try {
5759
let storeJson = JSON.stringify(this.store);
58-
await AsyncStorage.setItem(this.kUserStoreStorageKey, storeJson);
60+
const results = await AsyncStorage.setItem(this.kUserStoreStorageKey, storeJson);
61+
62+
console.log('User store updated successfully:', results);
63+
console.log('Current user store:', this.store);
64+
5965
} catch (e) {
6066
console.log('Error saving user store', e);
6167
}

0 commit comments

Comments
 (0)