QR code validation

I am developing an Ionic 4 app that should scan and validate QR code for claiming, using PhoneGap Plugin BarcodeScanner. The scanning is working as expected but I’m having difficulties on validating the QR code.

My idea is that the QR code is only valid for the user if the userID and PromotionID matches the QR Code (in Firestore database). I’m using the document ID’s to generate QR code For example, QR code ’ 075u6SGzsZ3tWq1v3Trb ’ and ’ XXDzN47QXqsGZIMeySw0 ’ can only be use by user123.


Below is the implementation

Example.page.ts:

qr: any;

scanQRCode () {
  this.options= {
  preferFrontCamera : false, 
  showFlipCameraButton : true, 
  showTorchButton:true,
  disableSuccessBeep: false,
  torchOn: false,
  prompt: 'Scan your QRcode'
};
this.subscription = this.afs.collection('claims')
 .snapshotChanges()
 .subscribe(data => {

  this.qr= data.map(e => {
    return {
      id: e.payload.doc.id,
      promotionID: e.payload.doc.data()['promotion'],
      userID: e.payload.doc.data()['user'],
    };
  })
  console.log(this.item);
  this.subscription.unsubscribe();
});

    this.scanner.scan(this.options).then((data) => {
      this.scannedData = data;
      if(this.qr.promotionID && this.qr.userID == data){
      this.navCtrl.navigateForward('/nextPage');
    }else{
      return this.presentAlert('Error','Invalid QRCODE')
    }

  }, (err) => {
  console.log('Error: ',err);
 })
}

Example.page.html

<ion-button expand="block" icon-left (click)="scanQRCode()"><ion-icon name="qr-scanner"></ion-icon>Scan code</ion-button>

I need help. Please be gentle since I am new to Ionic and Firebase. Thank you.

It’s not clear where you’re having a problem. Lets start with the basics…

  1. Is the user logged in?

  2. What info do you have about the user that ties them to a QR code? userId?

  3. Are you able to scan the QR code?

  4. Can you get the info off the QR code that you need?

  5. Can you determine that a user is eligible based on the user info and QR code info, or do you need to go to Firestore to get more info?

  6. What is it about the QR code data and your user that makes them eligible?

1 Like