Prevent access to user pages when not logged in [v2] (#8904)

* do not throw error when navigating

* enhance: add loginRequired to router

This allows client pages to require logging in before displaying the
page, useful for example for user settings pages.

* add login requirements

Co-authored-by: Andreas Nedbal <git@pixelde.su>
This commit is contained in:
Johann150
2022-06-29 11:26:06 +02:00
committed by GitHub
parent f997b7dff2
commit 7f111f4474
3 changed files with 34 additions and 1 deletions

View File

@@ -2,11 +2,13 @@
import { EventEmitter } from 'eventemitter3';
import { Ref, Component, ref, shallowRef, ShallowRef } from 'vue';
import { pleaseLogin } from '@/scripts/please-login';
type RouteDef = {
path: string;
component: Component;
query?: Record<string, string>;
loginRequired?: boolean;
name?: string;
hash?: string;
globalCacheKey?: string;
@@ -169,6 +171,10 @@ export class Router extends EventEmitter<{
throw new Error('no route found for: ' + path);
}
if (res.route.loginRequired) {
pleaseLogin('/');
}
const isSamePath = beforePath === path;
if (isSamePath && key == null) key = this.currentKey;
this.currentComponent = res.route.component;