mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-29 03:33:47 +02:00
refactor: use router handle login redirect
This commit is contained in:
98
src/views/Layout/AuthenticatedLayout.vue
Normal file
98
src/views/Layout/AuthenticatedLayout.vue
Normal file
@@ -0,0 +1,98 @@
|
||||
<template>
|
||||
<template v-if="watchState.isLoggedIn">
|
||||
<NavMenu></NavMenu>
|
||||
|
||||
<el-splitter @resize-end="setAsideWidth">
|
||||
<el-splitter-panel>
|
||||
<RouterView></RouterView>
|
||||
</el-splitter-panel>
|
||||
|
||||
<el-splitter-panel v-if="isSideBarTabShow" :min="250" :max="700" :size="asideWidth" collapsible>
|
||||
<Sidebar></Sidebar>
|
||||
</el-splitter-panel>
|
||||
</el-splitter>
|
||||
|
||||
<!-- ## Dialogs ## -->
|
||||
<UserDialog></UserDialog>
|
||||
|
||||
<WorldDialog></WorldDialog>
|
||||
|
||||
<AvatarDialog></AvatarDialog>
|
||||
|
||||
<GroupDialog></GroupDialog>
|
||||
|
||||
<GroupMemberModerationDialog></GroupMemberModerationDialog>
|
||||
|
||||
<InviteGroupDialog></InviteGroupDialog>
|
||||
|
||||
<FullscreenImagePreview></FullscreenImagePreview>
|
||||
|
||||
<PreviousInstancesInfoDialog></PreviousInstancesInfoDialog>
|
||||
|
||||
<LaunchDialog></LaunchDialog>
|
||||
|
||||
<LaunchOptionsDialog></LaunchOptionsDialog>
|
||||
|
||||
<FriendImportDialog></FriendImportDialog>
|
||||
|
||||
<WorldImportDialog></WorldImportDialog>
|
||||
|
||||
<AvatarImportDialog></AvatarImportDialog>
|
||||
|
||||
<ChooseFavoriteGroupDialog></ChooseFavoriteGroupDialog>
|
||||
|
||||
<VRChatConfigDialog></VRChatConfigDialog>
|
||||
|
||||
<PrimaryPasswordDialog></PrimaryPasswordDialog>
|
||||
|
||||
<SendBoopDialog></SendBoopDialog>
|
||||
|
||||
<ChangelogDialog></ChangelogDialog>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { watch } from 'vue';
|
||||
|
||||
import { useAppearanceSettingsStore } from '../../stores';
|
||||
import { watchState } from '../../service/watchState';
|
||||
|
||||
import AvatarDialog from '../../components/dialogs/AvatarDialog/AvatarDialog.vue';
|
||||
import AvatarImportDialog from '../Favorites/dialogs/AvatarImportDialog.vue';
|
||||
import ChangelogDialog from '../Settings/dialogs/ChangelogDialog.vue';
|
||||
import ChooseFavoriteGroupDialog from '../../components/dialogs/ChooseFavoriteGroupDialog.vue';
|
||||
import FriendImportDialog from '../Favorites/dialogs/FriendImportDialog.vue';
|
||||
import FullscreenImagePreview from '../../components/FullscreenImagePreview.vue';
|
||||
import GroupDialog from '../../components/dialogs/GroupDialog/GroupDialog.vue';
|
||||
import GroupMemberModerationDialog from '../../components/dialogs/GroupDialog/GroupMemberModerationDialog.vue';
|
||||
import InviteGroupDialog from '../../components/dialogs/InviteGroupDialog.vue';
|
||||
import LaunchDialog from '../../components/dialogs/LaunchDialog.vue';
|
||||
import LaunchOptionsDialog from '../Settings/dialogs/LaunchOptionsDialog.vue';
|
||||
import NavMenu from '../../components/NavMenu.vue';
|
||||
import PreviousInstancesInfoDialog from '../../components/dialogs/PreviousInstancesDialog/PreviousInstancesInfoDialog.vue';
|
||||
import PrimaryPasswordDialog from '../Settings/dialogs/PrimaryPasswordDialog.vue';
|
||||
import SendBoopDialog from '../../components/dialogs/SendBoopDialog.vue';
|
||||
import Sidebar from '../Sidebar/Sidebar.vue';
|
||||
import UserDialog from '../../components/dialogs/UserDialog/UserDialog.vue';
|
||||
import VRChatConfigDialog from '../Settings/dialogs/VRChatConfigDialog.vue';
|
||||
import WorldDialog from '../../components/dialogs/WorldDialog/WorldDialog.vue';
|
||||
import WorldImportDialog from '../Favorites/dialogs/WorldImportDialog.vue';
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const appearanceStore = useAppearanceSettingsStore();
|
||||
const { setAsideWidth } = appearanceStore;
|
||||
const { asideWidth, isSideBarTabShow } = storeToRefs(appearanceStore);
|
||||
|
||||
watch(
|
||||
() => watchState.isLoggedIn,
|
||||
(isLoggedIn) => {
|
||||
if (!isLoggedIn) {
|
||||
router.replace({ name: 'login' });
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
</script>
|
||||
@@ -148,8 +148,9 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onBeforeMount, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { Connection, Delete, Download } from '@element-plus/icons-vue';
|
||||
import { onBeforeMount, onBeforeUnmount, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
@@ -159,6 +160,8 @@
|
||||
import { watchState } from '../../service/watchState';
|
||||
|
||||
const { showVRCXUpdateDialog } = useVRCXUpdaterStore();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const { loginForm, enableCustomEndpoint } = storeToRefs(useAuthStore());
|
||||
const { toggleCustomEndpoint, relogin, deleteSavedLogin, login, getAllSavedCredentials } = useAuthStore();
|
||||
const { promptProxySettings } = useGeneralSettingsStore();
|
||||
@@ -196,6 +199,23 @@
|
||||
savedCredentials.value = await getAllSavedCredentials();
|
||||
}
|
||||
|
||||
function postLoginRedirect() {
|
||||
const redirect = route.query.redirect;
|
||||
if (typeof redirect === 'string' && redirect.startsWith('/') && redirect !== '/login') {
|
||||
return redirect;
|
||||
}
|
||||
return '/feed';
|
||||
}
|
||||
|
||||
watch(
|
||||
() => watchState.isLoggedIn,
|
||||
(isLoggedIn) => {
|
||||
if (isLoggedIn) {
|
||||
router.replace(postLoginRedirect());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
onBeforeMount(async () => {
|
||||
updateSavedCredentials();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user