remove if/else by using ternary operator
This commit is contained in:
1 parent
7a3d2619f6
commit
111f7d5a67
1 file changed
+3
-11
@@ -27,17 +27,9 @@ const { handleValidationError, handleError } = require("./controllerUtils");
|
|||||||
*/
|
*/
|
||||||
const issueToken = (payload, typeOfToken, appSettings) => {
|
const issueToken = (payload, typeOfToken, appSettings) => {
|
||||||
try {
|
try {
|
||||||
let tokenSecret, tokenTTL, payloadData = {};
|
const tokenTTL = (typeOfToken === tokenType.REFRESH_TOKEN) ? (appSettings?.refreshTokenTTL?? "7d") : (appSettings?.jwtTTL?? "2h");
|
||||||
|
const tokenSecret = (typeOfToken === tokenType.REFRESH_TOKEN) ? appSettings?.refreshTokenSecret : appSettings?.jwtSecret;
|
||||||
if(typeOfToken === tokenType.REFRESH_TOKEN) {
|
const payloadData = (typeOfToken === tokenType.REFRESH_TOKEN) ? {} : payload;
|
||||||
tokenSecret = appSettings.refreshTokenSecret;
|
|
||||||
tokenTTL = appSettings.refreshTokenTTL ? appSettings.refreshTokenTTL : "7d";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tokenSecret = appSettings.jwtSecret;
|
|
||||||
tokenTTL = appSettings.jwtTTL ? appSettings.jwtTTL : "2h";
|
|
||||||
payloadData = payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
return jwt.sign(payloadData, tokenSecret, { expiresIn: tokenTTL });
|
return jwt.sign(payloadData, tokenSecret, { expiresIn: tokenTTL });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in new issue
Block a user