Home > Blockchain >  How can I generate user's QR-code in node.js?
How can I generate user's QR-code in node.js?

Time:08-09

First off, I need some suggestions regarding QR code in my app.

I am building a parking-management app in node.js in which there are different tables like user, booking, parking etc.

Now, Users will search for parking availability and book one parking-slot and based on that details the QR code will be generated. now whenever user go to that parking place he needs to show that QR-code to the parking attendant. The parking attendant will scan the QR code and will verify the details and the in database there is a field called isStarted will become true(Initially it was false). So the questions are:

  1. Do I need to generate QR-code in the back-end and store it to the database or It will be generated from the front-end Side?(I think I don't need to generate it in the backend I just need to decrypt it)

  2. If it generates on the front-end then what approach should I take to decrypt it?

  3. It is not related to the QR-code but still asking. I want to notify the merchant(parking-owner) about the details of user who wants to park their vehicle in the merchant's space. How can I do that with node.js? I have some code already written by someone which is as following but I don't understand what it is.

     let notification_data = {
       name: `${owner.basicInfo.fullName}`,
       date: dayjs(req.body.date).format("MMM DD, YYYY"),
       startTime: req.body.startTime,
     };
    
     let { title, body } = notificationTypes.addBooking(notification_data);
    
     let data = {
       senderId: req.data.id,
       receiverId: req.body.walkerId,
       title,
       body,
     };
    
     sendNotification(data);
    

Can anyone here help me with above queries?

CodePudding user response:

You can leave the creation of the QR code to the frontend, but with the data that the backend sends to the frontend, and in this way, the frontend can also scan the photo and send the scanned data to the backend, and any necessary operation can be done in this way. You can also have the QR code through the back through the link below: https://www.npmjs.com/package/qrcode

Regarding question number three, you can also use FCM and web push mechanism.

CodePudding user response:

you're welcome, You can create a token user data in the backend by using the JWT library, and append in query link you want for example: https://example.com/page1?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlNWI4OTdmODhlMDYxMzFlZjA2MDA5OSIsInR5cGUiOiJ2aWV3ZXIiLCJ0b2tlblR5cGUiOiJhY2FkZW15IiwiaWF0IjoxNjU5MzU4MDE0f

and in page example.com/page1 send request to back-end with token in query and in back-end decrypt token and use it.

for notification use https://www.npmjs.com/package/fcm-node and send notification This link can help you : https://code-boxx.com/push-notifications-nodejs/

  • Related