mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-07 14:56:06 +02:00
Fix saving credentials
This commit is contained in:
+78
-53
@@ -71,7 +71,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const saveCredentials = ref(null);
|
const credentialsToSave = ref(null);
|
||||||
|
|
||||||
const twoFactorAuthDialogVisible = ref(false);
|
const twoFactorAuthDialogVisible = ref(false);
|
||||||
|
|
||||||
@@ -112,25 +112,33 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
async function init() {
|
async function init() {
|
||||||
const [savedCredentials, lastUserLoggedIn, enableCustomEndpoint] =
|
const [savedCredentials, lastUserLoggedIn, enableCustomEndpoint] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
configRepository.getString('savedCredentials'),
|
configRepository.getString('savedCredentials', '{}'),
|
||||||
configRepository.getString('lastUserLoggedIn'),
|
configRepository.getString('lastUserLoggedIn', ''),
|
||||||
configRepository.getBool('VRCX_enableCustomEndpoint', false)
|
configRepository.getBool('VRCX_enableCustomEndpoint', false)
|
||||||
]);
|
]);
|
||||||
|
loginForm.value.lastUserLoggedIn = lastUserLoggedIn;
|
||||||
try {
|
try {
|
||||||
loginForm.value = {
|
const credentials = JSON.parse(savedCredentials || '{}');
|
||||||
...loginForm.value,
|
// fix goofy typo
|
||||||
savedCredentials: savedCredentials
|
let edited = false;
|
||||||
? JSON.parse(savedCredentials)
|
for (const userId in credentials) {
|
||||||
: {},
|
if (credentials[userId].loginParmas) {
|
||||||
lastUserLoggedIn
|
credentials[userId].loginParams =
|
||||||
};
|
credentials[userId].loginParmas;
|
||||||
|
delete credentials[userId].loginParmas;
|
||||||
|
edited = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (edited) {
|
||||||
|
await configRepository.setString(
|
||||||
|
'savedCredentials',
|
||||||
|
JSON.stringify(credentials)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
loginForm.value.savedCredentials = credentials;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to parse savedCredentials:', error);
|
console.error('Failed to parse savedCredentials:', error);
|
||||||
loginForm.value = {
|
loginForm.value.savedCredentials = {};
|
||||||
...loginForm.value,
|
|
||||||
savedCredentials: {},
|
|
||||||
lastUserLoggedIn
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
state.enableCustomEndpoint = enableCustomEndpoint;
|
state.enableCustomEndpoint = enableCustomEndpoint;
|
||||||
}
|
}
|
||||||
@@ -146,6 +154,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
)}</strong>!`
|
)}</strong>!`
|
||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
|
userStore.userDialog.visible = false;
|
||||||
watchState.isLoggedIn = false;
|
watchState.isLoggedIn = false;
|
||||||
watchState.isFriendsLoaded = false;
|
watchState.isFriendsLoaded = false;
|
||||||
watchState.isFavoritesLoaded = false;
|
watchState.isFavoritesLoaded = false;
|
||||||
@@ -173,9 +182,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
loginForm.value.savedCredentials[
|
loginForm.value.savedCredentials[
|
||||||
loginForm.value.lastUserLoggedIn
|
loginForm.value.lastUserLoggedIn
|
||||||
];
|
];
|
||||||
if (user?.loginParmas?.endpoint) {
|
if (user?.loginParams?.endpoint) {
|
||||||
AppDebug.endpointDomain = user.loginParmas.endpoint;
|
AppDebug.endpointDomain = user.loginParams.endpoint;
|
||||||
AppDebug.websocketDomain = user.loginParmas.websocket;
|
AppDebug.websocketDomain = user.loginParams.websocket;
|
||||||
}
|
}
|
||||||
// login at startup
|
// login at startup
|
||||||
loginForm.value.loading = true;
|
loginForm.value.loading = true;
|
||||||
@@ -259,14 +268,14 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
security
|
security
|
||||||
.decrypt(
|
.decrypt(
|
||||||
loginForm.value.savedCredentials[userId]
|
loginForm.value.savedCredentials[userId]
|
||||||
.loginParmas.password,
|
.loginParams.password,
|
||||||
value
|
value
|
||||||
)
|
)
|
||||||
.then(async (pt) => {
|
.then(async (pt) => {
|
||||||
saveCredentials.value = {
|
credentialsToSave.value = {
|
||||||
username:
|
username:
|
||||||
loginForm.value.savedCredentials[userId]
|
loginForm.value.savedCredentials[userId]
|
||||||
.loginParmas.username,
|
.loginParams.username,
|
||||||
password: pt
|
password: pt
|
||||||
};
|
};
|
||||||
await updateStoredUser(
|
await updateStoredUser(
|
||||||
@@ -305,15 +314,15 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
for (const userId in loginForm.value.savedCredentials) {
|
for (const userId in loginForm.value.savedCredentials) {
|
||||||
security
|
security
|
||||||
.encrypt(
|
.encrypt(
|
||||||
loginForm.value.savedCredentials[userId].loginParmas
|
loginForm.value.savedCredentials[userId].loginParams
|
||||||
.password,
|
.password,
|
||||||
key
|
key
|
||||||
)
|
)
|
||||||
.then((ct) => {
|
.then((ct) => {
|
||||||
saveCredentials.value = {
|
credentialsToSave.value = {
|
||||||
username:
|
username:
|
||||||
loginForm.value.savedCredentials[userId]
|
loginForm.value.savedCredentials[userId]
|
||||||
.loginParmas.username,
|
.loginParams.username,
|
||||||
password: ct
|
password: ct
|
||||||
};
|
};
|
||||||
updateStoredUser(
|
updateStoredUser(
|
||||||
@@ -331,13 +340,18 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
await configRepository.getString('savedCredentials')
|
await configRepository.getString('savedCredentials')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (saveCredentials.value) {
|
if (credentialsToSave.value) {
|
||||||
const credentialsToSave = {
|
savedCredentials[user.id] = {
|
||||||
user,
|
user,
|
||||||
loginParmas: saveCredentials.value
|
loginParams: {
|
||||||
|
username: '',
|
||||||
|
password: '',
|
||||||
|
endpoint: '',
|
||||||
|
websocket: '',
|
||||||
|
...credentialsToSave.value
|
||||||
|
}
|
||||||
};
|
};
|
||||||
savedCredentials[user.id] = credentialsToSave;
|
credentialsToSave.value = null;
|
||||||
saveCredentials.value = null;
|
|
||||||
} else if (typeof savedCredentials[user.id] !== 'undefined') {
|
} else if (typeof savedCredentials[user.id] !== 'undefined') {
|
||||||
savedCredentials[user.id].user = user;
|
savedCredentials[user.id].user = user;
|
||||||
savedCredentials[user.id].cookies =
|
savedCredentials[user.id].cookies =
|
||||||
@@ -426,14 +440,14 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function relogin(user) {
|
async function relogin(user) {
|
||||||
const { loginParmas } = user;
|
const { loginParams } = user;
|
||||||
if (user.cookies) {
|
if (user.cookies) {
|
||||||
await webApiService.setCookies(user.cookies);
|
await webApiService.setCookies(user.cookies);
|
||||||
}
|
}
|
||||||
loginForm.value.lastUserLoggedIn = user.user.id; // for resend email 2fa
|
loginForm.value.lastUserLoggedIn = user.user.id; // for resend email 2fa
|
||||||
if (loginParmas.endpoint) {
|
if (loginParams.endpoint) {
|
||||||
AppDebug.endpointDomain = loginParmas.endpoint;
|
AppDebug.endpointDomain = loginParams.endpoint;
|
||||||
AppDebug.websocketDomain = loginParmas.websocket;
|
AppDebug.websocketDomain = loginParams.websocket;
|
||||||
} else {
|
} else {
|
||||||
AppDebug.endpointDomain = AppDebug.endpointDomainVrchat;
|
AppDebug.endpointDomain = AppDebug.endpointDomainVrchat;
|
||||||
AppDebug.websocketDomain = AppDebug.websocketDomainVrchat;
|
AppDebug.websocketDomain = AppDebug.websocketDomainVrchat;
|
||||||
@@ -441,7 +455,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
loginForm.value.loading = true;
|
loginForm.value.loading = true;
|
||||||
if (advancedSettingsStore.enablePrimaryPassword) {
|
if (advancedSettingsStore.enablePrimaryPassword) {
|
||||||
checkPrimaryPassword(loginParmas)
|
checkPrimaryPassword(loginParams)
|
||||||
.then((pwd) => {
|
.then((pwd) => {
|
||||||
return authRequest
|
return authRequest
|
||||||
.getConfig()
|
.getConfig()
|
||||||
@@ -450,11 +464,11 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
authLogin({
|
authLogin({
|
||||||
username: loginParmas.username,
|
username: loginParams.username,
|
||||||
password: pwd,
|
password: pwd,
|
||||||
cipher: loginParmas.password,
|
cipher: loginParams.password,
|
||||||
endpoint: loginParmas.endpoint,
|
endpoint: loginParams.endpoint,
|
||||||
websocket: loginParmas.websocket
|
websocket: loginParams.websocket
|
||||||
})
|
})
|
||||||
.catch((err2) => {
|
.catch((err2) => {
|
||||||
reject(err2);
|
reject(err2);
|
||||||
@@ -479,10 +493,10 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
authLogin({
|
authLogin({
|
||||||
username: loginParmas.username,
|
username: loginParams.username,
|
||||||
password: loginParmas.password,
|
password: loginParams.password,
|
||||||
endpoint: loginParmas.endpoint,
|
endpoint: loginParams.endpoint,
|
||||||
websocket: loginParmas.websocket
|
websocket: loginParams.websocket
|
||||||
})
|
})
|
||||||
.catch((err2) => {
|
.catch((err2) => {
|
||||||
handleLogoutEvent();
|
handleLogoutEvent();
|
||||||
@@ -557,7 +571,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
];
|
];
|
||||||
security
|
security
|
||||||
.decrypt(
|
.decrypt(
|
||||||
saveCredential.loginParmas.password,
|
saveCredential.loginParams.password,
|
||||||
value
|
value
|
||||||
)
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -731,21 +745,32 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {{ username: string, password: string, saveCredentials: any, cipher: string }} params credential to login
|
* @param {{ username: string, password: string, endpoint: string, websocket: string, saveCredentials?: any, cipher?: string }} params credential to login
|
||||||
* @returns {Promise<{origin: boolean, json: any}>}
|
* @returns {Promise<{origin: boolean, json: any}>}
|
||||||
*/
|
*/
|
||||||
function authLogin(params) {
|
function authLogin(params) {
|
||||||
let { username, password, saveCredentials, cipher } = params;
|
let {
|
||||||
username = encodeURIComponent(username);
|
username,
|
||||||
password = encodeURIComponent(password);
|
password,
|
||||||
const auth = btoa(`${username}:${password}`);
|
endpoint,
|
||||||
|
websocket,
|
||||||
|
saveCredentials,
|
||||||
|
cipher
|
||||||
|
} = params;
|
||||||
|
const auth = btoa(
|
||||||
|
`${encodeURIComponent(username)}:${encodeURIComponent(password)}`
|
||||||
|
);
|
||||||
if (saveCredentials) {
|
if (saveCredentials) {
|
||||||
delete params.saveCredentials;
|
params.saveCredentials = false;
|
||||||
if (cipher) {
|
if (cipher) {
|
||||||
params.password = cipher;
|
password = cipher;
|
||||||
delete params.cipher;
|
|
||||||
}
|
}
|
||||||
saveCredentials.value = params;
|
credentialsToSave.value = {
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
endpoint,
|
||||||
|
websocket
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return request('auth/user', {
|
return request('auth/user', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -852,7 +877,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
|
|
||||||
loginForm,
|
loginForm,
|
||||||
enablePrimaryPasswordDialog,
|
enablePrimaryPasswordDialog,
|
||||||
saveCredentials,
|
credentialsToSave,
|
||||||
twoFactorAuthDialogVisible,
|
twoFactorAuthDialogVisible,
|
||||||
cachedConfig,
|
cachedConfig,
|
||||||
enableCustomEndpoint,
|
enableCustomEndpoint,
|
||||||
|
|||||||
@@ -111,7 +111,7 @@
|
|||||||
<div class="detail">
|
<div class="detail">
|
||||||
<span class="name" v-text="user.user.displayName"></span>
|
<span class="name" v-text="user.user.displayName"></span>
|
||||||
<span class="extra" v-text="user.user.username"></span>
|
<span class="extra" v-text="user.user.username"></span>
|
||||||
<span class="extra" v-text="user.loginParmas.endpoint"></span>
|
<span class="extra" v-text="user.loginParams.endpoint"></span>
|
||||||
</div>
|
</div>
|
||||||
<el-button
|
<el-button
|
||||||
type="default"
|
type="default"
|
||||||
|
|||||||
Reference in New Issue
Block a user