Skip to content

Commit

Permalink
fix: correctly handle simluator
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Sep 13, 2024
1 parent 0c1a8f6 commit 1eadfbd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ausweis-example/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function App() {
new AusweisAuthFlow({
debug: true,
// Can set to true to allow simulator cards
allowSimulatorCard: false,
allowSimulatorCard: true,
onEnterPin: ({ attemptsRemaining }) => {
// Mock incorrect pin entry
return attemptsRemaining === 1 ? '123456' : '123123'
Expand Down
12 changes: 6 additions & 6 deletions src/AusweisAuthFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,15 @@ export class AusweisAuthFlow {
if (message.msg === 'READER') {
// If card is empty object the card is unknown, we see that as no card attached for this flow
const isSimulator = message.name === 'Simulator'

// Return early if simulator not allowed. As we don't want to emit events related to that
if (isSimulator && !this.options.allowSimulatorCard) return

const isCardAttached =
message.attached &&
(isSimulator || (message.card !== null && message.card !== undefined && Object.keys(message.card).length > 0))

if (isSimulator) this.isSimulatorCardAttached = isCardAttached
console.log({
isCardAttached,
isSimulator,
isSimulatorCardAttached: this.isSimulatorCardAttached,
})

this.options.onCardAttachedChanged?.({
isCardAttached,
Expand All @@ -270,11 +269,12 @@ export class AusweisAuthFlow {
}

if (message.msg === 'INSERT_CARD') {
if (this.options.allowSimulatorCard && this.isSimulatorCardAttached) {
if (this.options.allowSimulatorCard) {
this.sendCommand({
cmd: 'SET_CARD',
name: 'Simulator',
})
this.isSimulatorCardAttached = true
return
}
this.options.onAttachCard?.()
Expand Down

0 comments on commit 1eadfbd

Please sign in to comment.