mirror of
https://github.com/multipleof4/ntfy.git
synced 2026-10-13 15:15:24 +00:00
Sw stuff
This commit is contained in:
@@ -342,10 +342,16 @@ class AccountApi {
|
||||
|
||||
async sync() {
|
||||
try {
|
||||
// For proxy auth, store the username from config if not already in session
|
||||
if (config.auth_user && !session.exists()) {
|
||||
console.log(`[AccountApi] Proxy auth: storing session for user ${config.auth_user}`);
|
||||
await session.store(config.auth_user, ""); // Empty token for proxy auth
|
||||
// For proxy auth, detect user from /v1/account if no session exists
|
||||
if (config.auth_mode === AuthMode.PROXY && !session.exists()) {
|
||||
console.log(`[AccountApi] Proxy auth mode, detecting user from /v1/account`);
|
||||
const account = await this.get();
|
||||
// Never store "*" (anonymous) as username
|
||||
if (account.username && account.username !== "*") {
|
||||
console.log(`[AccountApi] Proxy auth: storing session for ${account.username}`);
|
||||
await session.store(account.username, ""); // Empty token for proxy auth
|
||||
}
|
||||
return account;
|
||||
}
|
||||
if (!session.exists()) {
|
||||
return null;
|
||||
@@ -373,6 +379,11 @@ class AccountApi {
|
||||
} catch (e) {
|
||||
console.log(`[AccountApi] Error fetching account`, e);
|
||||
if (e instanceof UnauthorizedError) {
|
||||
// For proxy auth, hard refresh to get fresh auth from proxy
|
||||
if (config.auth_mode === AuthMode.PROXY) {
|
||||
window.location.reload();
|
||||
return undefined;
|
||||
}
|
||||
await session.resetAndRedirect(routes.login);
|
||||
}
|
||||
return undefined;
|
||||
@@ -437,5 +448,10 @@ export const Permission = {
|
||||
DENY_ALL: "deny-all",
|
||||
};
|
||||
|
||||
// Maps to apiConfigResponse.AuthMode in server/types.go
|
||||
export const AuthMode = {
|
||||
PROXY: "proxy",
|
||||
};
|
||||
|
||||
const accountApi = new AccountApi();
|
||||
export default accountApi;
|
||||
|
||||
@@ -16,7 +16,7 @@ import routes from "./routes";
|
||||
import db from "../app/db";
|
||||
import { topicDisplayName } from "../app/utils";
|
||||
import Navigation from "./Navigation";
|
||||
import accountApi from "../app/AccountApi";
|
||||
import accountApi, { AuthMode } from "../app/AccountApi";
|
||||
import PopupMenu from "./PopupMenu";
|
||||
import { SubscriptionPopup } from "./SubscriptionPopup";
|
||||
import { useIsLaunchedPWA } from "./hooks";
|
||||
@@ -140,7 +140,7 @@ const ProfileIcon = () => {
|
||||
|
||||
const handleLogout = async () => {
|
||||
// For proxy auth, redirect to the logout URL if configured
|
||||
if (config.auth_user) {
|
||||
if (config.auth_mode === AuthMode.PROXY) {
|
||||
if (config.auth_logout_url) {
|
||||
await db().delete();
|
||||
localStorage.removeItem("user");
|
||||
@@ -159,7 +159,7 @@ const ProfileIcon = () => {
|
||||
};
|
||||
|
||||
// Determine if logout button should be shown (hide if proxy auth without logout URL)
|
||||
const showLogout = !config.auth_user || config.auth_logout_url;
|
||||
const showLogout = config.auth_mode !== AuthMode.PROXY || config.auth_logout_url;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -5,7 +5,7 @@ import WarningAmberIcon from "@mui/icons-material/WarningAmber";
|
||||
import { NavLink } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Visibility, VisibilityOff } from "@mui/icons-material";
|
||||
import accountApi from "../app/AccountApi";
|
||||
import accountApi, { AuthMode } from "../app/AccountApi";
|
||||
import AvatarBox from "./AvatarBox";
|
||||
import session from "../app/Session";
|
||||
import routes from "./routes";
|
||||
@@ -20,7 +20,7 @@ const Login = () => {
|
||||
|
||||
// Redirect to app if using proxy authentication
|
||||
useEffect(() => {
|
||||
if (config.auth_user) {
|
||||
if (config.auth_mode === AuthMode.PROXY) {
|
||||
window.location.href = routes.app;
|
||||
}
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user