fix: 非ログイン時にクレデンシャルが必要なページに行くとエラーが出る問題を修正 (#10973)

* 非ログイン時にクレデンシャルが必要なページに行くとエラーが出る問題を修正 (misskey-dev/misskey#10922)

* Update CHANGELOG.md

* fix

* Update CHANGELOG.md

* Update CHANGELOG.md
This commit is contained in:
Chocolate Pie 2023-07-08 08:58:35 +09:00 committed by GitHub
parent 8ec96ad1e0
commit bd843863d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 9 deletions

View file

@ -20,6 +20,7 @@
### Client ### Client
- Fix: サーバーメトリクスが90度傾いている - Fix: サーバーメトリクスが90度傾いている
- Fix: 非ログイン時にクレデンシャルが必要なページに行くとエラーが出る問題を修正
- Fix: sparkle内にリンクを入れるとクリック不能になる問題の修正 - Fix: sparkle内にリンクを入れるとクリック不能になる問題の修正
- Fix: ZenUIでポップアップの表示位置がおかしい問題を修正 - Fix: ZenUIでポップアップの表示位置がおかしい問題を修正
- deck UIのカラムのメニューからアンテナとリストの編集画面を開けるように - deck UIのカラムのメニューからアンテナとリストの編集画面を開けるように

View file

@ -30,7 +30,8 @@ import MkWindow from '@/components/MkWindow.vue';
import { popout as _popout } from '@/scripts/popout'; import { popout as _popout } from '@/scripts/popout';
import copyToClipboard from '@/scripts/copy-to-clipboard'; import copyToClipboard from '@/scripts/copy-to-clipboard';
import { url } from '@/config'; import { url } from '@/config';
import { mainRouter, routes } from '@/router'; import { mainRouter, routes, page } from '@/router';
import { $i } from '@/account';
import { Router } from '@/nirax'; import { Router } from '@/nirax';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { PageMetadata, provideMetadataReceiver } from '@/scripts/page-metadata'; import { PageMetadata, provideMetadataReceiver } from '@/scripts/page-metadata';
@ -45,7 +46,7 @@ defineEmits<{
(ev: 'closed'): void; (ev: 'closed'): void;
}>(); }>();
const router = new Router(routes, props.initialPath); const router = new Router(routes, props.initialPath, !!$i, page(() => import('@/pages/not-found.vue')));
let pageMetadata = $ref<null | ComputedRef<PageMetadata>>(); let pageMetadata = $ref<null | ComputedRef<PageMetadata>>();
let windowEl = $shallowRef<InstanceType<typeof MkWindow>>(); let windowEl = $shallowRef<InstanceType<typeof MkWindow>>();

View file

@ -2,7 +2,6 @@
import { EventEmitter } from 'eventemitter3'; import { EventEmitter } from 'eventemitter3';
import { Component, shallowRef, ShallowRef } from 'vue'; import { Component, shallowRef, ShallowRef } from 'vue';
import { pleaseLogin } from '@/scripts/please-login';
import { safeURIDecode } from '@/scripts/safe-uri-decode'; import { safeURIDecode } from '@/scripts/safe-uri-decode';
type RouteDef = { type RouteDef = {
@ -23,7 +22,7 @@ type ParsedPath = (string | {
optional?: boolean; optional?: boolean;
})[]; })[];
export type Resolved = { route: RouteDef; props: Map<string, string>; child?: Resolved; }; export type Resolved = { route: RouteDef; props: Map<string, string | boolean>; child?: Resolved; };
function parsePath(path: string): ParsedPath { function parsePath(path: string): ParsedPath {
const res = [] as ParsedPath; const res = [] as ParsedPath;
@ -75,15 +74,19 @@ export class Router extends EventEmitter<{
public currentRef: ShallowRef<Resolved> = shallowRef(); public currentRef: ShallowRef<Resolved> = shallowRef();
public currentRoute: ShallowRef<RouteDef> = shallowRef(); public currentRoute: ShallowRef<RouteDef> = shallowRef();
private currentPath: string; private currentPath: string;
private isLoggedIn: boolean;
private notFoundPageComponent: Component;
private currentKey = Date.now().toString(); private currentKey = Date.now().toString();
public navHook: ((path: string, flag?: any) => boolean) | null = null; public navHook: ((path: string, flag?: any) => boolean) | null = null;
constructor(routes: Router['routes'], currentPath: Router['currentPath']) { constructor(routes: Router['routes'], currentPath: Router['currentPath'], isLoggedIn: boolean, notFoundPageComponent: Component) {
super(); super();
this.routes = routes; this.routes = routes;
this.currentPath = currentPath; this.currentPath = currentPath;
this.isLoggedIn = isLoggedIn;
this.notFoundPageComponent = notFoundPageComponent;
this.navigate(currentPath, null, false); this.navigate(currentPath, null, false);
} }
@ -212,8 +215,9 @@ export class Router extends EventEmitter<{
throw new Error('no route found for: ' + path); throw new Error('no route found for: ' + path);
} }
if (res.route.loginRequired) { if (res.route.loginRequired && !this.isLoggedIn) {
pleaseLogin('/'); res.route.component = this.notFoundPageComponent;
res.props.set('showLoginPopup', true);
} }
const isSamePath = beforePath === path; const isSamePath = beforePath === path;

View file

@ -10,8 +10,17 @@
<script lang="ts" setup> <script lang="ts" setup>
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
import { pleaseLogin } from '@/scripts/please-login';
import { notFoundImageUrl } from '@/instance'; import { notFoundImageUrl } from '@/instance';
const props = defineProps<{
showLoginPopup?: boolean;
}>();
if (props.showLoginPopup) {
pleaseLogin('/');
}
const headerActions = $computed(() => []); const headerActions = $computed(() => []);
const headerTabs = $computed(() => []); const headerTabs = $computed(() => []);

View file

@ -4,7 +4,7 @@ import { $i, iAmModerator } from '@/account';
import MkLoading from '@/pages/_loading_.vue'; import MkLoading from '@/pages/_loading_.vue';
import MkError from '@/pages/_error_.vue'; import MkError from '@/pages/_error_.vue';
const page = (loader: AsyncComponentLoader<any>) => defineAsyncComponent({ export const page = (loader: AsyncComponentLoader<any>) => defineAsyncComponent({
loader: loader, loader: loader,
loadingComponent: MkLoading, loadingComponent: MkLoading,
errorComponent: MkError, errorComponent: MkError,
@ -505,7 +505,7 @@ export const routes = [{
component: page(() => import('./pages/not-found.vue')), component: page(() => import('./pages/not-found.vue')),
}]; }];
export const mainRouter = new Router(routes, location.pathname + location.search + location.hash); export const mainRouter = new Router(routes, location.pathname + location.search + location.hash, !!$i, page(() => import('@/pages/not-found.vue')));
window.history.replaceState({ key: mainRouter.getCurrentKey() }, '', location.href); window.history.replaceState({ key: mainRouter.getCurrentKey() }, '', location.href);