Gate certain features by requiring a logged in user.
This commit is contained in:
parent
8a7132c276
commit
809943edcc
|
@ -1,5 +1,10 @@
|
|||
import {type JSX, render} from "preact";
|
||||
import {extractGroups, initializeGlobals, log} from "../utilities/exports.js";
|
||||
import {
|
||||
extractGroups,
|
||||
initializeGlobals,
|
||||
log,
|
||||
userIsLoggedIn,
|
||||
} from "../utilities/exports.js";
|
||||
import {
|
||||
Data,
|
||||
Feature,
|
||||
|
@ -36,6 +41,11 @@ async function initialize() {
|
|||
const knownGroups = await fromStorage(Data.KnownGroups);
|
||||
const userLabels = await fromStorage(Feature.UserLabels);
|
||||
|
||||
const isLoggedIn = userIsLoggedIn();
|
||||
if (!isLoggedIn) {
|
||||
log("User is not logged in, running with limited features enabled.", true);
|
||||
}
|
||||
|
||||
// Only when any of the features that uses this data are enabled, try to save
|
||||
// the groups.
|
||||
if (
|
||||
|
@ -89,7 +99,7 @@ async function initialize() {
|
|||
});
|
||||
}
|
||||
|
||||
if (enabledFeatures.value.has(Feature.MarkdownToolbar)) {
|
||||
if (enabledFeatures.value.has(Feature.MarkdownToolbar) && isLoggedIn) {
|
||||
observerFeatures.push(() => {
|
||||
runMarkdownToolbarFeature();
|
||||
});
|
||||
|
@ -121,7 +131,7 @@ async function initialize() {
|
|||
// Object to hold the active components we are going to render.
|
||||
const components: Record<string, JSX.Element | undefined> = {};
|
||||
|
||||
if (enabledFeatures.value.has(Feature.Autocomplete)) {
|
||||
if (enabledFeatures.value.has(Feature.Autocomplete) && isLoggedIn) {
|
||||
components.autocomplete = (
|
||||
<AutocompleteFeature
|
||||
anonymizeUsernamesEnabled={anonymizeUsernamesEnabled}
|
||||
|
@ -135,7 +145,7 @@ async function initialize() {
|
|||
components.backToTop = <BackToTopFeature />;
|
||||
}
|
||||
|
||||
if (enabledFeatures.value.has(Feature.JumpToNewComment)) {
|
||||
if (enabledFeatures.value.has(Feature.JumpToNewComment) && isLoggedIn) {
|
||||
components.jumpToNewComment = <JumpToNewCommentFeature />;
|
||||
}
|
||||
|
||||
|
@ -152,11 +162,17 @@ async function initialize() {
|
|||
runCommentAnchorFixFeature();
|
||||
}
|
||||
|
||||
if (miscEnabled.value.has(MiscellaneousFeature.GroupListSubscribeButtons)) {
|
||||
if (
|
||||
miscEnabled.value.has(MiscellaneousFeature.GroupListSubscribeButtons) &&
|
||||
isLoggedIn
|
||||
) {
|
||||
runGroupListSubscribeButtonFeature();
|
||||
}
|
||||
|
||||
if (miscEnabled.value.has(MiscellaneousFeature.TopicInfoIgnore)) {
|
||||
if (
|
||||
miscEnabled.value.has(MiscellaneousFeature.TopicInfoIgnore) &&
|
||||
isLoggedIn
|
||||
) {
|
||||
runTopicInfoIgnore();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,4 +7,5 @@ export * from "./logging.js";
|
|||
export * from "./query-selectors.js";
|
||||
export * from "./report-a-bug.js";
|
||||
export * from "./text.js";
|
||||
export * from "./user.js";
|
||||
export * from "./validators.js";
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Checks whether a user is logged in on or not.
|
||||
*/
|
||||
export function userIsLoggedIn(): boolean {
|
||||
return document.querySelector(".logged-in-user-username") !== null;
|
||||
}
|
Loading…
Reference in New Issue