Skip to content

Commit 1eadfbd

Browse files
committed
fix: correctly handle simluator
Signed-off-by: Timo Glastra <[email protected]>
1 parent 0c1a8f6 commit 1eadfbd

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

ausweis-example/app/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function App() {
2525
new AusweisAuthFlow({
2626
debug: true,
2727
// Can set to true to allow simulator cards
28-
allowSimulatorCard: false,
28+
allowSimulatorCard: true,
2929
onEnterPin: ({ attemptsRemaining }) => {
3030
// Mock incorrect pin entry
3131
return attemptsRemaining === 1 ? '123456' : '123123'

src/AusweisAuthFlow.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,15 @@ export class AusweisAuthFlow {
246246
if (message.msg === 'READER') {
247247
// If card is empty object the card is unknown, we see that as no card attached for this flow
248248
const isSimulator = message.name === 'Simulator'
249+
250+
// Return early if simulator not allowed. As we don't want to emit events related to that
251+
if (isSimulator && !this.options.allowSimulatorCard) return
252+
249253
const isCardAttached =
250254
message.attached &&
251255
(isSimulator || (message.card !== null && message.card !== undefined && Object.keys(message.card).length > 0))
252256

253257
if (isSimulator) this.isSimulatorCardAttached = isCardAttached
254-
console.log({
255-
isCardAttached,
256-
isSimulator,
257-
isSimulatorCardAttached: this.isSimulatorCardAttached,
258-
})
259258

260259
this.options.onCardAttachedChanged?.({
261260
isCardAttached,
@@ -270,11 +269,12 @@ export class AusweisAuthFlow {
270269
}
271270

272271
if (message.msg === 'INSERT_CARD') {
273-
if (this.options.allowSimulatorCard && this.isSimulatorCardAttached) {
272+
if (this.options.allowSimulatorCard) {
274273
this.sendCommand({
275274
cmd: 'SET_CARD',
276275
name: 'Simulator',
277276
})
277+
this.isSimulatorCardAttached = true
278278
return
279279
}
280280
this.options.onAttachCard?.()

0 commit comments

Comments
 (0)