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

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