Redirect to login page if require-login is enabled

This commit is contained in:
binwiederhier
2025-08-24 13:48:19 -04:00
parent ec1f97b726
commit 3de04b27ab
8 changed files with 20 additions and 36 deletions

View File

@@ -97,8 +97,6 @@
"notifications_none_for_any_description": "To send notifications to a topic, simply PUT or POST to the topic URL. Here's an example using one of your topics.",
"notifications_no_subscriptions_title": "It looks like you don't have any subscriptions yet.",
"notifications_no_subscriptions_description": "Click the \"{{linktext}}\" link to create or subscribe to a topic. After that, you can send messages via PUT or POST and you'll receive notifications here.",
"notifications_no_subscriptions_login_title": "This page requires a Login.",
"notifications_no_subscriptions_login_description": "Click \"{{linktext}}\" to login into your account.",
"notifications_example": "Example",
"notifications_more_details": "For more information, check out the <websiteLink>website</websiteLink> or <docsLink>documentation</docsLink>.",
"display_name_dialog_title": "Change display name",

View File

@@ -135,7 +135,7 @@ const NavList = (props) => {
{showNotificationContextNotSupportedBox && <NotificationContextNotSupportedAlert />}
{showNotificationIOSInstallRequired && <NotificationIOSInstallRequiredAlert />}
{alertVisible && <Divider />}
{!showSubscriptionsList && (session.exists() || !config.require_login) && (
{!showSubscriptionsList && (
<ListItemButton onClick={() => navigate(routes.app)} selected={location.pathname === config.app_root}>
<ListItemIcon>
<ChatBubble />
@@ -164,36 +164,30 @@ const NavList = (props) => {
<ListItemText primary={t("nav_button_account")} />
</ListItemButton>
)}
{session.exists() || !config.require_login && (
<ListItemButton onClick={() => navigate(routes.settings)} selected={location.pathname === routes.settings}>
<ListItemIcon>
<SettingsIcon />
</ListItemIcon>
<ListItemText primary={t("nav_button_settings")} />
</ListItemButton>
)}
<ListItemButton onClick={() => openUrl("/docs")}>
<ListItemIcon>
<ArticleIcon />
</ListItemIcon>
<ListItemText primary={t("nav_button_documentation")} />
</ListItemButton>
{session.exists() || !config.require_login && (
<ListItemButton onClick={() => props.onPublishMessageClick()}>
<ListItemIcon>
<Send />
</ListItemIcon>
<ListItemText primary={t("nav_button_publish_message")} />
</ListItemButton>
)}
{session.exists() || !config.require_login && (
<ListItemButton onClick={() => setSubscribeDialogOpen(true)}>
<ListItemIcon>
<AddIcon />
</ListItemIcon>
<ListItemText primary={t("nav_button_subscribe")} />
</ListItemButton>
)}
{showUpgradeBanner && (
// The text background gradient didn't seem to do well with switching between light/dark mode,
// So adding a `key` forces React to replace the entire component when the theme changes

View File

@@ -46,7 +46,6 @@ import priority5 from "../img/priority-5.svg";
import logoOutline from "../img/ntfy-outline.svg";
import AttachmentIcon from "./AttachmentIcon";
import { useAutoSubscribe } from "./hooks";
import session from "../app/Session";
const priorityFiles = {
1: priority1,
@@ -645,16 +644,12 @@ const NoSubscriptions = () => {
<Typography variant="h5" align="center" sx={{ paddingBottom: 1 }}>
<img src={logoOutline} height="64" width="64" alt={t("action_bar_logo_alt")} />
<br />
{!session.exists() && !config.require_login && t("notifications_no_subscriptions_title")}
{!session.exists() && config.require_login && t("notifications_no_subscriptions_login_title")}
{t("notifications_no_subscriptions_title")}
</Typography>
<Paragraph>
{!session.exists() && !config.require_login && t("notifications_no_subscriptions_description", {
{t("notifications_no_subscriptions_description", {
linktext: t("nav_button_subscribe"),
})}
{!session.exists() && config.require_login && t("notifications_no_subscriptions_login_description", {
linktext: t("action_bar_sign_in"),
})}
</Paragraph>
<Paragraph>
<ForMoreDetails />

View File

@@ -65,22 +65,16 @@ const maybeUpdateAccountSettings = async (payload) => {
}
};
const Preferences = () => {
if (!session.exists() or !config.requireLogin) {
window.location.href = routes.app;
return <></>;
}
return (
<Container maxWidth="md" sx={{ marginTop: 3, marginBottom: 3 }}>
<Stack spacing={3}>
<Notifications />
<Reservations />
<Users />
<Appearance />
</Stack>
</Container>
);
};
const Preferences = () => (
<Container maxWidth="md" sx={{ marginTop: 3, marginBottom: 3 }}>
<Stack spacing={3}>
<Notifications />
<Reservations />
<Users />
<Appearance />
</Stack>
</Container>
);
const Notifications = () => {
const { t } = useTranslation();