mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-05 22:36:05 +02:00
refactor coordinators
This commit is contained in:
@@ -1,56 +1,61 @@
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import Noty from 'noty';
|
||||
|
||||
import { closeWebSocket, initWebsocket } from '../service/websocket';
|
||||
import { escapeTag } from '../shared/utils';
|
||||
import { queryClient } from '../queries';
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
import { useNotificationStore } from '../stores/notification';
|
||||
import { useUpdateLoopStore } from '../stores/updateLoop';
|
||||
import { useUserStore } from '../stores/user';
|
||||
import { watchState } from '../service/watchState';
|
||||
|
||||
import configRepository from '../service/config';
|
||||
import webApiService from '../service/webapi';
|
||||
|
||||
/**
|
||||
* @param {object} deps Coordinator dependencies.
|
||||
* @returns {object} Auth flow coordinator methods.
|
||||
* Runs the shared logout side effects (including goodbye notification).
|
||||
*/
|
||||
export function createAuthCoordinator(deps) {
|
||||
const {
|
||||
userStore,
|
||||
notificationStore,
|
||||
updateLoopStore,
|
||||
initWebsocket,
|
||||
updateStoredUser,
|
||||
webApiService,
|
||||
loginForm,
|
||||
configRepository,
|
||||
setAttemptingAutoLogin,
|
||||
autoLoginAttempts,
|
||||
closeWebSocket,
|
||||
queryClient,
|
||||
watchState
|
||||
} = deps;
|
||||
export async function runLogoutFlow() {
|
||||
const authStore = useAuthStore();
|
||||
const userStore = useUserStore();
|
||||
const notificationStore = useNotificationStore();
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* Runs the shared logout side effects.
|
||||
*/
|
||||
async function runLogoutFlow() {
|
||||
userStore.setUserDialogVisible(false);
|
||||
watchState.isLoggedIn = false;
|
||||
watchState.isFriendsLoaded = false;
|
||||
watchState.isFavoritesLoaded = false;
|
||||
notificationStore.setNotificationInitStatus(false);
|
||||
await updateStoredUser(userStore.currentUser);
|
||||
webApiService.clearCookies();
|
||||
loginForm.value.lastUserLoggedIn = '';
|
||||
// workerTimers.setTimeout(() => location.reload(), 500);
|
||||
await configRepository.remove('lastUserLoggedIn');
|
||||
setAttemptingAutoLogin(false);
|
||||
autoLoginAttempts.clear();
|
||||
closeWebSocket();
|
||||
queryClient.clear();
|
||||
if (watchState.isLoggedIn) {
|
||||
new Noty({
|
||||
type: 'success',
|
||||
text: t('message.auth.logout_greeting', {
|
||||
name: `<strong>${escapeTag(userStore.currentUser.displayName)}</strong>`
|
||||
})
|
||||
}).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs post-login side effects after a successful auth response.
|
||||
* @param {object} json Current user payload from auth API.
|
||||
*/
|
||||
function runLoginSuccessFlow(json) {
|
||||
updateLoopStore.setNextCurrentUserRefresh(420); // 7mins
|
||||
userStore.applyCurrentUser(json);
|
||||
initWebsocket();
|
||||
}
|
||||
|
||||
return {
|
||||
runLogoutFlow,
|
||||
runLoginSuccessFlow
|
||||
};
|
||||
userStore.setUserDialogVisible(false);
|
||||
watchState.isLoggedIn = false;
|
||||
watchState.isFriendsLoaded = false;
|
||||
watchState.isFavoritesLoaded = false;
|
||||
notificationStore.setNotificationInitStatus(false);
|
||||
await authStore.updateStoredUser(userStore.currentUser);
|
||||
webApiService.clearCookies();
|
||||
authStore.loginForm.lastUserLoggedIn = '';
|
||||
await configRepository.remove('lastUserLoggedIn');
|
||||
authStore.setAttemptingAutoLogin(false);
|
||||
authStore.state.autoLoginAttempts.clear();
|
||||
closeWebSocket();
|
||||
queryClient.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs post-login side effects after a successful auth response.
|
||||
* @param {object} json Current user payload from auth API.
|
||||
*/
|
||||
export function runLoginSuccessFlow(json) {
|
||||
const updateLoopStore = useUpdateLoopStore();
|
||||
const userStore = useUserStore();
|
||||
|
||||
updateLoopStore.setNextCurrentUserRefresh(420); // 7mins
|
||||
userStore.applyCurrentUser(json);
|
||||
initWebsocket();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user