mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-07 06:56:04 +02:00
fix TanStack Query cache and cachedUsers not being cleared on logout
This commit is contained in:
@@ -10,6 +10,7 @@ import { AppDebug } from '../service/appConfig';
|
|||||||
import { authRequest } from '../api';
|
import { authRequest } from '../api';
|
||||||
import { database } from '../service/database';
|
import { database } from '../service/database';
|
||||||
import { escapeTag } from '../shared/utils';
|
import { escapeTag } from '../shared/utils';
|
||||||
|
import { queryClient } from '../query';
|
||||||
import { request } from '../service/request';
|
import { request } from '../service/request';
|
||||||
import { useAdvancedSettingsStore } from './settings/advanced';
|
import { useAdvancedSettingsStore } from './settings/advanced';
|
||||||
import { useGeneralSettingsStore } from './settings/general';
|
import { useGeneralSettingsStore } from './settings/general';
|
||||||
@@ -98,6 +99,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
{ flush: 'sync' }
|
{ flush: 'sync' }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function init() {
|
async function init() {
|
||||||
const [lastUserLoggedIn, enableCustomEndpoint] = await Promise.all([
|
const [lastUserLoggedIn, enableCustomEndpoint] = await Promise.all([
|
||||||
configRepository.getString('lastUserLoggedIn', ''),
|
configRepository.getString('lastUserLoggedIn', ''),
|
||||||
@@ -109,6 +113,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function getAllSavedCredentials() {
|
async function getAllSavedCredentials() {
|
||||||
let savedCredentials = {};
|
let savedCredentials = {};
|
||||||
try {
|
try {
|
||||||
@@ -146,11 +153,18 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
return savedCredentials;
|
return savedCredentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param userId
|
||||||
|
*/
|
||||||
async function getSavedCredentials(userId) {
|
async function getSavedCredentials(userId) {
|
||||||
const savedCredentials = await getAllSavedCredentials();
|
const savedCredentials = await getAllSavedCredentials();
|
||||||
return savedCredentials[userId];
|
return savedCredentials[userId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function handleLogoutEvent() {
|
async function handleLogoutEvent() {
|
||||||
if (watchState.isLoggedIn) {
|
if (watchState.isLoggedIn) {
|
||||||
new Noty({
|
new Noty({
|
||||||
@@ -173,6 +187,7 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
attemptingAutoLogin.value = false;
|
attemptingAutoLogin.value = false;
|
||||||
state.autoLoginAttempts.clear();
|
state.autoLoginAttempts.clear();
|
||||||
closeWebSocket();
|
closeWebSocket();
|
||||||
|
queryClient.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,6 +229,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function clearCookiesTryLogin() {
|
async function clearCookiesTryLogin() {
|
||||||
await webApiService.clearCookies();
|
await webApiService.clearCookies();
|
||||||
if (loginForm.value.lastUserLoggedIn) {
|
if (loginForm.value.lastUserLoggedIn) {
|
||||||
@@ -227,6 +245,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function resendEmail2fa() {
|
async function resendEmail2fa() {
|
||||||
if (loginForm.value.lastUserLoggedIn) {
|
if (loginForm.value.lastUserLoggedIn) {
|
||||||
const user = await getSavedCredentials(
|
const user = await getSavedCredentials(
|
||||||
@@ -250,6 +271,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function enablePrimaryPasswordChange() {
|
function enablePrimaryPasswordChange() {
|
||||||
advancedSettingsStore.enablePrimaryPassword =
|
advancedSettingsStore.enablePrimaryPassword =
|
||||||
!advancedSettingsStore.enablePrimaryPassword;
|
!advancedSettingsStore.enablePrimaryPassword;
|
||||||
@@ -319,6 +343,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function setPrimaryPassword() {
|
async function setPrimaryPassword() {
|
||||||
await configRepository.setBool(
|
await configRepository.setBool(
|
||||||
'enablePrimaryPassword',
|
'enablePrimaryPassword',
|
||||||
@@ -343,6 +370,10 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
async function updateStoredUser(user) {
|
async function updateStoredUser(user) {
|
||||||
const savedCredentials = await getAllSavedCredentials();
|
const savedCredentials = await getAllSavedCredentials();
|
||||||
if (credentialsToSave.value) {
|
if (credentialsToSave.value) {
|
||||||
@@ -371,6 +402,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
await configRepository.setString('lastUserLoggedIn', user.id);
|
await configRepository.setString('lastUserLoggedIn', user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function migrateStoredUsers() {
|
async function migrateStoredUsers() {
|
||||||
const savedCredentials = await getAllSavedCredentials();
|
const savedCredentials = await getAllSavedCredentials();
|
||||||
for (const name in savedCredentials) {
|
for (const name in savedCredentials) {
|
||||||
@@ -386,6 +420,10 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
function checkPrimaryPassword(args) {
|
function checkPrimaryPassword(args) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!advancedSettingsStore.enablePrimaryPassword) {
|
if (!advancedSettingsStore.enablePrimaryPassword) {
|
||||||
@@ -413,6 +451,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function toggleCustomEndpoint() {
|
async function toggleCustomEndpoint() {
|
||||||
await configRepository.setBool(
|
await configRepository.setBool(
|
||||||
'VRCX_enableCustomEndpoint',
|
'VRCX_enableCustomEndpoint',
|
||||||
@@ -422,6 +463,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
loginForm.value.websocket = '';
|
loginForm.value.websocket = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function logout() {
|
function logout() {
|
||||||
modalStore
|
modalStore
|
||||||
.confirm({
|
.confirm({
|
||||||
@@ -441,6 +485,10 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
async function relogin(user) {
|
async function relogin(user) {
|
||||||
const { loginParams } = user;
|
const { loginParams } = user;
|
||||||
if (user.cookies) {
|
if (user.cookies) {
|
||||||
@@ -490,6 +538,10 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param userId
|
||||||
|
*/
|
||||||
async function deleteSavedLogin(userId) {
|
async function deleteSavedLogin(userId) {
|
||||||
const savedCredentials = await getAllSavedCredentials();
|
const savedCredentials = await getAllSavedCredentials();
|
||||||
delete savedCredentials[userId];
|
delete savedCredentials[userId];
|
||||||
@@ -510,6 +562,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function login() {
|
async function login() {
|
||||||
// TODO: remove/refactor saveCredentials & primaryPassword (security)
|
// TODO: remove/refactor saveCredentials & primaryPassword (security)
|
||||||
await webApiService.clearCookies();
|
await webApiService.clearCookies();
|
||||||
@@ -606,6 +661,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function promptTOTP() {
|
function promptTOTP() {
|
||||||
if (twoFactorAuthDialogVisible.value) {
|
if (twoFactorAuthDialogVisible.value) {
|
||||||
return;
|
return;
|
||||||
@@ -646,6 +704,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function promptOTP() {
|
function promptOTP() {
|
||||||
if (twoFactorAuthDialogVisible.value) {
|
if (twoFactorAuthDialogVisible.value) {
|
||||||
return;
|
return;
|
||||||
@@ -685,6 +746,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function promptEmailOTP() {
|
function promptEmailOTP() {
|
||||||
if (twoFactorAuthDialogVisible.value) {
|
if (twoFactorAuthDialogVisible.value) {
|
||||||
return;
|
return;
|
||||||
@@ -768,6 +832,10 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param json
|
||||||
|
*/
|
||||||
function handleCurrentUserUpdate(json) {
|
function handleCurrentUserUpdate(json) {
|
||||||
if (
|
if (
|
||||||
json.requiresTwoFactorAuth &&
|
json.requiresTwoFactorAuth &&
|
||||||
@@ -783,6 +851,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function handleAutoLogin() {
|
async function handleAutoLogin() {
|
||||||
if (attemptingAutoLogin.value) {
|
if (attemptingAutoLogin.value) {
|
||||||
return;
|
return;
|
||||||
@@ -850,6 +921,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function applyAutoLoginDelay() {
|
async function applyAutoLoginDelay() {
|
||||||
if (!generalSettingsStore.autoLoginDelayEnabled) {
|
if (!generalSettingsStore.autoLoginDelayEnabled) {
|
||||||
return;
|
return;
|
||||||
@@ -878,6 +952,9 @@ export const useAuthStore = defineStore('Auth', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
async function loginComplete() {
|
async function loginComplete() {
|
||||||
await database.initUserTables(userStore.currentUser.id);
|
await database.initUserTables(userStore.currentUser.id);
|
||||||
watchState.isLoggedIn = true;
|
watchState.isLoggedIn = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user