mirror of
https://github.com/balzack/databag.git
synced 2025-02-11 19:19:16 +00:00
support backward compatibility with admin login
This commit is contained in:
parent
5bd9d80258
commit
8a9216a934
@ -2,8 +2,10 @@ import { useState, useEffect, useContext } from 'react';
|
||||
import { useWindowDimensions } from 'react-native';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { AppContext } from 'context/AppContext';
|
||||
import { getNodeStatus } from 'api/getNodeStatus';
|
||||
import { setNodeStatus } from 'api/setNodeStatus';
|
||||
import { setNodeAccess } from 'api/setNodeAccess';
|
||||
import { getNodeConfig } from 'api/getNodeConfig';
|
||||
import { getLanguageStrings } from 'constants/Strings';
|
||||
|
||||
export function useAdmin() {
|
||||
@ -90,16 +92,23 @@ export function useAdmin() {
|
||||
try {
|
||||
const session = await setNodeAccess(node, state.token, state.mfaCode);
|
||||
updateState({ server: node, busy: false });
|
||||
navigate('/dashboard', { state: { server: node, token: session }});
|
||||
navigate('/dashboard', { state: { server: node, token: session, mfa: true }});
|
||||
}
|
||||
catch (err) {
|
||||
if (err.message == '405' || err.message == '403' || err.message == '429') {
|
||||
updateState({ mfaModal: true, mfaError: err.message });
|
||||
}
|
||||
else {
|
||||
console.log(err.message);
|
||||
updateState({ busy: false, showAlert: true });
|
||||
throw new Error('login failed');
|
||||
try {
|
||||
await getNodeConfig(node, state.token);
|
||||
updateState({ server: node, busy: false });
|
||||
navigate('/dashboard', { state: { server: node, token: state.token, mfa: false }});
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err.message);
|
||||
updateState({ busy: false, showAlert: true });
|
||||
throw new Error('login failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ import { InputCode } from 'utils/InputCode';
|
||||
export function Dashboard(props) {
|
||||
|
||||
const location = useLocation();
|
||||
const { server, token } = location.state;
|
||||
const { state, actions } = useDashboard(server, token);
|
||||
const { server, token, mfa } = location.state;
|
||||
const { state, actions } = useDashboard(server, token, mfa);
|
||||
|
||||
const enableMFA = async () => {
|
||||
try {
|
||||
@ -121,12 +121,12 @@ export function Dashboard(props) {
|
||||
<TouchableOpacity onPress={actions.showEditConfig}>
|
||||
<AntIcon style={styles.icon} name={'setting'} size={20} />
|
||||
</TouchableOpacity>
|
||||
{ !state.mfaEnabled && (
|
||||
{ !state.mfaEnabled && mfa && (
|
||||
<TouchableOpacity onPress={enableMFA}>
|
||||
<MatIcon style={styles.icon} name={'shield-lock-open-outline'} size={20} />
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
{ state.mfaEnabled && (
|
||||
{ state.mfaEnabled && mfa && (
|
||||
<TouchableOpacity onPress={disableMFA}>
|
||||
<MatIcon style={styles.icon} name={'shield-lock-outline'} size={20} />
|
||||
</TouchableOpacity>
|
||||
|
@ -20,7 +20,7 @@ import { addAdminMFAuth } from 'api/addAdminMFAuth';
|
||||
import { setAdminMFAuth } from 'api/setAdminMFAuth';
|
||||
import { removeAdminMFAuth } from 'api/removeAdminMFAuth';
|
||||
|
||||
export function useDashboard(server, token) {
|
||||
export function useDashboard(server, token, mfa) {
|
||||
|
||||
const [state, setState] = useState({
|
||||
strings: getLanguageStrings(),
|
||||
@ -74,7 +74,7 @@ export function useDashboard(server, token) {
|
||||
}
|
||||
|
||||
const syncNode = async () => {
|
||||
const mfaEnabled = await getAdminMFAuth(server, token);
|
||||
const mfaEnabled = mfa ? await getAdminMFAuth(server, token) : false;
|
||||
const config = await getNodeConfig(server, token);
|
||||
const nodeAccounts = await getNodeAccounts(server, token);
|
||||
const accounts = nodeAccounts.map(setAccountItem);
|
||||
|
Loading…
Reference in New Issue
Block a user