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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user