| 1234567891011121314151617181920212223242526272829303132333435 |
- const { validation } = require('./validation')
- const response = require('../utils/responseHandler')
- const jwt = require('jsonwebtoken')
- module.exports = [
- validation((req) => req.body, { otp: 'string' }),
- (req, res, next) => {
- if (!req.cookies['sidali-otp']) {
- return response.error(res, {
- code: 401,
- message: 'Unauthorized',
- })
- }
- const token = req.cookies['sidali-otp']
- jwt.verify(token, process.env.SRU51, async (err, data) => {
- if (err) {
- return response.error(res, {
- code: 401,
- message: 'Unauthorized',
- })
- }
- if (req.body.otp !== data.otp) {
- return response.error(res, {
- message: 'OTP tidak valid',
- code: 401
- })
- }
- req.no_hp = data.no_hp
- res.clearCookie('sidali-otp')
- return next()
- })
- }
- ]
|