nextblogkit 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -49
- package/dist/admin/index.cjs +48 -12
- package/dist/admin/index.cjs.map +1 -1
- package/dist/admin/index.js +48 -12
- package/dist/admin/index.js.map +1 -1
- package/dist/styles/admin.css +10 -0
- package/package.json +1 -1
package/dist/admin/index.js
CHANGED
|
@@ -104,22 +104,56 @@ function AdminLayout({ children, apiKey, apiPath, adminPath = "/admin/blog", bas
|
|
|
104
104
|
setBasePath(basePath);
|
|
105
105
|
}
|
|
106
106
|
}, [apiPath, basePath]);
|
|
107
|
+
const [initializing, setInitializing] = useState(true);
|
|
107
108
|
useEffect(() => {
|
|
108
|
-
if (typeof window
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
if (typeof window === "undefined") return;
|
|
110
|
+
setCurrentPath(window.location.pathname);
|
|
111
|
+
const stored = sessionStorage.getItem("nbk_api_key");
|
|
112
|
+
const key = stored || apiKey;
|
|
113
|
+
if (!key) {
|
|
114
|
+
setInitializing(false);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const base = apiPath || "/api/blog";
|
|
118
|
+
fetch(`${base}/settings`, {
|
|
119
|
+
headers: { Authorization: `Bearer ${key}` }
|
|
120
|
+
}).then((res) => {
|
|
121
|
+
if (res.ok) {
|
|
112
122
|
setIsAuthenticated(true);
|
|
123
|
+
} else {
|
|
124
|
+
sessionStorage.removeItem("nbk_api_key");
|
|
113
125
|
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
}).catch(() => {
|
|
127
|
+
if (key) setIsAuthenticated(true);
|
|
128
|
+
}).finally(() => setInitializing(false));
|
|
129
|
+
}, [apiKey, apiPath]);
|
|
130
|
+
const [loginError, setLoginError] = useState("");
|
|
131
|
+
const [loginLoading, setLoginLoading] = useState(false);
|
|
132
|
+
const handleLogin = async (e) => {
|
|
117
133
|
e.preventDefault();
|
|
118
|
-
if (inputKey.trim())
|
|
119
|
-
|
|
120
|
-
|
|
134
|
+
if (!inputKey.trim()) return;
|
|
135
|
+
setLoginError("");
|
|
136
|
+
setLoginLoading(true);
|
|
137
|
+
try {
|
|
138
|
+
const base = apiPath || "/api/blog";
|
|
139
|
+
const res = await fetch(`${base}/settings`, {
|
|
140
|
+
headers: { Authorization: `Bearer ${inputKey}` }
|
|
141
|
+
});
|
|
142
|
+
if (res.ok) {
|
|
143
|
+
sessionStorage.setItem("nbk_api_key", inputKey);
|
|
144
|
+
setIsAuthenticated(true);
|
|
145
|
+
} else {
|
|
146
|
+
setLoginError("Invalid API key");
|
|
147
|
+
}
|
|
148
|
+
} catch {
|
|
149
|
+
setLoginError("Unable to connect to server");
|
|
150
|
+
} finally {
|
|
151
|
+
setLoginLoading(false);
|
|
121
152
|
}
|
|
122
153
|
};
|
|
154
|
+
if (initializing) {
|
|
155
|
+
return /* @__PURE__ */ jsx("div", { className: "nbk-admin-login", children: /* @__PURE__ */ jsx("div", { className: "nbk-login-card", children: /* @__PURE__ */ jsx("p", { className: "nbk-login-subtitle", children: "Verifying..." }) }) });
|
|
156
|
+
}
|
|
123
157
|
if (!isAuthenticated) {
|
|
124
158
|
return /* @__PURE__ */ jsx("div", { className: "nbk-admin-login", children: /* @__PURE__ */ jsxs("div", { className: "nbk-login-card", children: [
|
|
125
159
|
/* @__PURE__ */ jsx("h1", { className: "nbk-login-title", children: "Blog Admin" }),
|
|
@@ -133,10 +167,12 @@ function AdminLayout({ children, apiKey, apiPath, adminPath = "/admin/blog", bas
|
|
|
133
167
|
onChange: (e) => setInputKey(e.target.value),
|
|
134
168
|
placeholder: "Enter API key",
|
|
135
169
|
className: "nbk-login-input",
|
|
136
|
-
autoFocus: true
|
|
170
|
+
autoFocus: true,
|
|
171
|
+
disabled: loginLoading
|
|
137
172
|
}
|
|
138
173
|
),
|
|
139
|
-
/* @__PURE__ */ jsx("
|
|
174
|
+
loginError && /* @__PURE__ */ jsx("p", { className: "nbk-login-error", children: loginError }),
|
|
175
|
+
/* @__PURE__ */ jsx("button", { type: "submit", className: "nbk-login-btn", disabled: loginLoading, children: loginLoading ? "Verifying..." : "Sign In" })
|
|
140
176
|
] })
|
|
141
177
|
] }) });
|
|
142
178
|
}
|