2024-09-07 10:21:41 -07:00
|
|
|
import {generateSecret} from 'time2fa';
|
|
|
|
|
|
|
|
function generateTOTPSecret() {
|
|
|
|
return {success: 'true', message: generateSecret()};
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTotpEnabled() {
|
|
|
|
if (process.env.TOTP_ENABLED === undefined) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (process.env.TOTP_ENABLED.toLocaleLowerCase() !== 'true') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTOTPStatus() {
|
2024-09-07 11:41:54 -07:00
|
|
|
const totpEnabled = getTotpEnabled();
|
|
|
|
return {success: true, message: totpEnabled, enabled: getTotpEnabled()};
|
2024-09-07 10:21:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function getSecret() {
|
|
|
|
return process.env.TOTP_SECRET;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
generateSecret: generateTOTPSecret,
|
|
|
|
getTOTPStatus,
|
|
|
|
getSecret
|
|
|
|
};
|