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

Issue

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?

Solution

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/

Answered By – Erfan Ebrahimi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published