mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-07 06:56:04 +02:00
Clean up savedCredentials again
This commit is contained in:
+37
-52
@@ -107,60 +107,55 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
const [savedCredentials, lastUserLoggedIn, enableCustomEndpoint] =
|
const [lastUserLoggedIn, enableCustomEndpoint] = await Promise.all([
|
||||||
await Promise.all([
|
|
||||||
configRepository.getString('savedCredentials', '{}'),
|
|
||||||
configRepository.getString('lastUserLoggedIn', ''),
|
configRepository.getString('lastUserLoggedIn', ''),
|
||||||
configRepository.getBool('VRCX_enableCustomEndpoint', false)
|
configRepository.getBool('VRCX_enableCustomEndpoint', false)
|
||||||
]);
|
]);
|
||||||
loginForm.value.lastUserLoggedIn = lastUserLoggedIn;
|
loginForm.value.lastUserLoggedIn = lastUserLoggedIn;
|
||||||
|
state.enableCustomEndpoint = enableCustomEndpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
async function getAllSavedCredentials() {
|
||||||
|
let savedCredentials = {};
|
||||||
try {
|
try {
|
||||||
const credentials = JSON.parse(savedCredentials || '{}');
|
savedCredentials = JSON.parse(
|
||||||
|
await configRepository.getString('savedCredentials', '{}')
|
||||||
|
);
|
||||||
let edited = false;
|
let edited = false;
|
||||||
for (const userId in credentials) {
|
for (const userId in savedCredentials) {
|
||||||
// fix goofy typo
|
// fix goofy typo
|
||||||
if (credentials[userId].loginParmas) {
|
if (savedCredentials[userId].loginParmas) {
|
||||||
credentials[userId].loginParams =
|
savedCredentials[userId].loginParams =
|
||||||
credentials[userId].loginParmas;
|
savedCredentials[userId].loginParmas;
|
||||||
delete credentials[userId].loginParmas;
|
delete savedCredentials[userId].loginParmas;
|
||||||
edited = true;
|
edited = true;
|
||||||
}
|
}
|
||||||
// fix missing fields
|
// fix missing fields
|
||||||
if (!credentials[userId].loginParams.endpoint) {
|
if (!savedCredentials[userId].loginParams.endpoint) {
|
||||||
credentials[userId].loginParams.endpoint = '';
|
savedCredentials[userId].loginParams.endpoint = '';
|
||||||
edited = true;
|
edited = true;
|
||||||
}
|
}
|
||||||
if (!credentials[userId].loginParams.websocket) {
|
if (!savedCredentials[userId].loginParams.websocket) {
|
||||||
credentials[userId].loginParams.websocket = '';
|
savedCredentials[userId].loginParams.websocket = '';
|
||||||
edited = true;
|
edited = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (edited) {
|
if (edited) {
|
||||||
await configRepository.setString(
|
await configRepository.setString(
|
||||||
'savedCredentials',
|
'savedCredentials',
|
||||||
JSON.stringify(credentials)
|
JSON.stringify(savedCredentials)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to parse savedCredentials:', error);
|
|
||||||
}
|
|
||||||
state.enableCustomEndpoint = enableCustomEndpoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
async function getSavedCredentials(userId) {
|
|
||||||
let savedCredentials = {};
|
|
||||||
try {
|
|
||||||
savedCredentials = JSON.parse(
|
|
||||||
await configRepository.getString('savedCredentials', '{}')
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to get saved credentials:', e);
|
console.error('Failed to get saved credentials:', e);
|
||||||
}
|
}
|
||||||
if (!savedCredentials) {
|
return savedCredentials;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getSavedCredentials(userId) {
|
||||||
|
const savedCredentials = await getAllSavedCredentials();
|
||||||
return savedCredentials[userId];
|
return savedCredentials[userId];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,7 +275,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(async ({ value }) => {
|
.then(async ({ value }) => {
|
||||||
let savedCredentials = JSON.parse(
|
const savedCredentials = JSON.parse(
|
||||||
await configRepository.getString(
|
await configRepository.getString(
|
||||||
'savedCredentials',
|
'savedCredentials',
|
||||||
'{}'
|
'{}'
|
||||||
@@ -331,9 +326,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
enablePrimaryPasswordDialog.value.visible = false;
|
enablePrimaryPasswordDialog.value.visible = false;
|
||||||
if (advancedSettingsStore.enablePrimaryPassword) {
|
if (advancedSettingsStore.enablePrimaryPassword) {
|
||||||
const key = enablePrimaryPasswordDialog.value.password;
|
const key = enablePrimaryPasswordDialog.value.password;
|
||||||
let savedCredentials = JSON.parse(
|
const savedCredentials = await getAllSavedCredentials();
|
||||||
await configRepository.getString('savedCredentials', '{}')
|
|
||||||
);
|
|
||||||
for (const userId in savedCredentials) {
|
for (const userId in savedCredentials) {
|
||||||
security
|
security
|
||||||
.encrypt(savedCredentials[userId].loginParams.password, key)
|
.encrypt(savedCredentials[userId].loginParams.password, key)
|
||||||
@@ -350,12 +343,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function updateStoredUser(user) {
|
async function updateStoredUser(user) {
|
||||||
let savedCredentials = {};
|
const savedCredentials = await getAllSavedCredentials();
|
||||||
if ((await configRepository.getString('savedCredentials')) !== null) {
|
|
||||||
savedCredentials = JSON.parse(
|
|
||||||
await configRepository.getString('savedCredentials')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (credentialsToSave.value) {
|
if (credentialsToSave.value) {
|
||||||
savedCredentials[user.id] = {
|
savedCredentials[user.id] = {
|
||||||
user,
|
user,
|
||||||
@@ -383,12 +371,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function migrateStoredUsers() {
|
async function migrateStoredUsers() {
|
||||||
let savedCredentials = {};
|
const savedCredentials = await getAllSavedCredentials();
|
||||||
if ((await configRepository.getString('savedCredentials')) !== null) {
|
|
||||||
savedCredentials = JSON.parse(
|
|
||||||
await configRepository.getString('savedCredentials')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for (const name in savedCredentials) {
|
for (const name in savedCredentials) {
|
||||||
const userId = savedCredentials[name]?.user?.id;
|
const userId = savedCredentials[name]?.user?.id;
|
||||||
if (userId && userId !== name) {
|
if (userId && userId !== name) {
|
||||||
@@ -526,9 +509,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function deleteSavedLogin(userId) {
|
async function deleteSavedLogin(userId) {
|
||||||
const savedCredentials = JSON.parse(
|
const savedCredentials = await getAllSavedCredentials();
|
||||||
await configRepository.getString('savedCredentials')
|
|
||||||
);
|
|
||||||
delete savedCredentials[userId];
|
delete savedCredentials[userId];
|
||||||
// Disable primary password when no account is available.
|
// Disable primary password when no account is available.
|
||||||
if (Object.keys(savedCredentials).length === 0) {
|
if (Object.keys(savedCredentials).length === 0) {
|
||||||
@@ -828,12 +809,14 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAutoLogin() {
|
async function handleAutoLogin() {
|
||||||
if (attemptingAutoLogin.value) {
|
if (attemptingAutoLogin.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
attemptingAutoLogin.value = true;
|
attemptingAutoLogin.value = true;
|
||||||
const user = getSavedCredentials(loginForm.value.lastUserLoggedIn);
|
const user = await getSavedCredentials(
|
||||||
|
loginForm.value.lastUserLoggedIn
|
||||||
|
);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
attemptingAutoLogin.value = false;
|
attemptingAutoLogin.value = false;
|
||||||
return;
|
return;
|
||||||
@@ -859,6 +842,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state.autoLoginAttempts.add(new Date().getTime());
|
state.autoLoginAttempts.add(new Date().getTime());
|
||||||
|
console.log('Attempting automatic login...');
|
||||||
relogin(user)
|
relogin(user)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (AppDebug.errorNoty) {
|
if (AppDebug.errorNoty) {
|
||||||
@@ -924,6 +908,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
handleAutoLogin,
|
handleAutoLogin,
|
||||||
handleLogoutEvent,
|
handleLogoutEvent,
|
||||||
handleCurrentUserUpdate,
|
handleCurrentUserUpdate,
|
||||||
loginComplete
|
loginComplete,
|
||||||
|
getAllSavedCredentials
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -158,11 +158,9 @@
|
|||||||
import { AppDebug } from '../../service/appConfig';
|
import { AppDebug } from '../../service/appConfig';
|
||||||
import { watchState } from '../../service/watchState';
|
import { watchState } from '../../service/watchState';
|
||||||
|
|
||||||
import configRepository from '../../service/config';
|
|
||||||
|
|
||||||
const { showVRCXUpdateDialog } = useVRCXUpdaterStore();
|
const { showVRCXUpdateDialog } = useVRCXUpdaterStore();
|
||||||
const { loginForm, enableCustomEndpoint } = storeToRefs(useAuthStore());
|
const { loginForm, enableCustomEndpoint } = storeToRefs(useAuthStore());
|
||||||
const { toggleCustomEndpoint, relogin, deleteSavedLogin, login } = useAuthStore();
|
const { toggleCustomEndpoint, relogin, deleteSavedLogin, login, getAllSavedCredentials } = useAuthStore();
|
||||||
const { promptProxySettings } = useGeneralSettingsStore();
|
const { promptProxySettings } = useGeneralSettingsStore();
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
@@ -195,12 +193,7 @@
|
|||||||
if (watchState.isLoggedIn) {
|
if (watchState.isLoggedIn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
savedCredentials.value = await getAllSavedCredentials();
|
||||||
savedCredentials.value = JSON.parse(await configRepository.getString('savedCredentials')) || {};
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to parse saved credentials:', e);
|
|
||||||
savedCredentials.value = {};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
onBeforeMount(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user