static login fix it
This commit is contained in:
Vendored
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>CITPL Admin</title>
|
<title>CITPL Admin</title>
|
||||||
<script type="module" crossorigin src="/citpl_website/assets/admin-Blm7TeBi.js"></script>
|
<script type="module" crossorigin src="/citpl_website/assets/admin-D28kGkNT.js"></script>
|
||||||
<link rel="modulepreload" crossorigin href="/citpl_website/assets/x-DnG5sti3.js">
|
<link rel="modulepreload" crossorigin href="/citpl_website/assets/x-DnG5sti3.js">
|
||||||
<link rel="stylesheet" crossorigin href="/citpl_website/assets/admin-yhMCgkf-.css">
|
<link rel="stylesheet" crossorigin href="/citpl_website/assets/admin-yhMCgkf-.css">
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
+1
File diff suppressed because one or more lines are too long
+2
-2
@@ -168,8 +168,8 @@ function LoginPreview() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Login({ onLogin }) {
|
function Login({ onLogin }) {
|
||||||
const [username, setUsername] = useState('');
|
const [username, setUsername] = useState('admin');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('admin123');
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
|||||||
+33
-3
@@ -1,5 +1,10 @@
|
|||||||
import { API_BASE } from '../lib/apiBase';
|
import { API_BASE } from '../lib/apiBase';
|
||||||
|
|
||||||
|
/** Frontend-only fallback when the Node API is not reachable on the host. */
|
||||||
|
const STATIC_USER = 'admin';
|
||||||
|
const STATIC_PASS = 'admin123';
|
||||||
|
export const STATIC_TOKEN = 'static-admin-session';
|
||||||
|
|
||||||
export function getToken() {
|
export function getToken() {
|
||||||
return localStorage.getItem('admin_token');
|
return localStorage.getItem('admin_token');
|
||||||
}
|
}
|
||||||
@@ -12,6 +17,17 @@ export function clearToken() {
|
|||||||
localStorage.removeItem('admin_token');
|
localStorage.removeItem('admin_token');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isStaticSession(token = getToken()) {
|
||||||
|
return token === STATIC_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
function staticLogin(username, password) {
|
||||||
|
if (username === STATIC_USER && password === STATIC_PASS) {
|
||||||
|
return { token: STATIC_TOKEN, expiresAt: null, mode: 'static' };
|
||||||
|
}
|
||||||
|
throw new Error('Invalid credentials');
|
||||||
|
}
|
||||||
|
|
||||||
async function apiFetch(path, options = {}) {
|
async function apiFetch(path, options = {}) {
|
||||||
const headers = { ...options.headers };
|
const headers = { ...options.headers };
|
||||||
if (!(options.body instanceof FormData)) {
|
if (!(options.body instanceof FormData)) {
|
||||||
@@ -35,10 +51,24 @@ async function apiFetch(path, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const adminApi = {
|
export const adminApi = {
|
||||||
login: (username, password) =>
|
login: async (username, password) => {
|
||||||
apiFetch('/api/auth/login', { method: 'POST', body: JSON.stringify({ username, password }) }),
|
// Prefer Node API when it is up; otherwise allow static admin/admin123.
|
||||||
|
try {
|
||||||
|
return await apiFetch('/api/auth/login', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ username, password }),
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
return staticLogin(username, password);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
me: () => apiFetch('/api/auth/me'),
|
me: async () => {
|
||||||
|
if (isStaticSession()) {
|
||||||
|
return { username: STATIC_USER, mode: 'static' };
|
||||||
|
}
|
||||||
|
return apiFetch('/api/auth/me');
|
||||||
|
},
|
||||||
|
|
||||||
getContent: () => apiFetch('/api/content'),
|
getContent: () => apiFetch('/api/content'),
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user