36 lines
833 B
TypeScript
36 lines
833 B
TypeScript
import { DASHBOARD_ROUTE } from "../routes";
|
|
import LiteElement from "../utils/LiteElement";
|
|
import type { AuthState } from "../utils/AuthService";
|
|
import type { CurrentUser } from "../types/user";
|
|
|
|
/**
|
|
* Block rendering and dispatch event if user is not logged in
|
|
*
|
|
* Usage example:
|
|
* ```ts
|
|
* @needLogin
|
|
* MyComponent extends LiteElement {}
|
|
* ```
|
|
*/
|
|
export function needLogin<T extends { new (...args: any[]): LiteElement }>(
|
|
constructor: T
|
|
) {
|
|
return class extends constructor {
|
|
authState?: AuthState;
|
|
|
|
static get properties() {
|
|
return {
|
|
authState: { type: Object },
|
|
};
|
|
}
|
|
|
|
update(changedProperties: Map<string, any>) {
|
|
if (this.authState) {
|
|
super.update(changedProperties);
|
|
} else {
|
|
this.dispatchEvent(new CustomEvent("need-login"));
|
|
}
|
|
}
|
|
};
|
|
}
|