-
-
Save DanyF-github/71212f534e16f3387cc68b33f146ad9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server/src/graphql/vonage.js | |
... | |
const verifyRequestResolver = async (_, { number }, __, ___) => { | |
try { | |
const requestId = await verifyRequest(number); | |
return { | |
requestId, | |
}; | |
} catch (err) { | |
console.error(err); | |
throw new Error(INTERNAL_ERROR); | |
} | |
}; | |
const checkCodeResolver = async (_, { requestId, code, number }, __, ___) => { | |
try { | |
const result = await checkCode(code, requestId); | |
// if verification is successful, we return a JWT token | |
if (result) { | |
const [student] = students.filter( | |
(student) => student.phoneNumber === number | |
); | |
// create the token | |
const token = jwt.sign( | |
{ | |
phoneNumber: student.phoneNumber, | |
}, | |
accessTokenSecret, | |
{ | |
expiresIn: '15min', | |
} | |
); | |
return { | |
token, | |
}; | |
} else { | |
return { | |
token: null, | |
}; | |
} | |
} catch (err) { | |
console.error('An error ocurred when trying to check code', err); | |
return { | |
token: null, | |
}; | |
} | |
}; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment