Added demo access

This commit is contained in:
blaisadmin
2026-03-26 09:59:40 -04:00
parent 45c6d03f8d
commit 8b7763cf13
5 changed files with 116 additions and 1 deletions
+35
View File
@@ -110,6 +110,7 @@ type PublicProvider = {
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:5000/api';
const allowRegistration = (import.meta.env.VITE_ALLOW_REGISTRATION ?? 'true').toLowerCase() !== 'false';
const allowDemoAccount = (import.meta.env.VITE_ALLOW_DEMO_ACCOUNT ?? 'false').toLowerCase() === 'true';
const tokenStorageKey = 'arsenal-iq-token';
const profileStorageKey = 'arsenal-iq-profile';
const ammoPageSelectionKey = 'arsenal-iq-ammo-page-calibers';
@@ -533,6 +534,31 @@ export default function Home() {
}
};
const handleDemoLogin = async () => {
setSaving(true);
setError('');
setMessage('');
try {
const payload = await apiFetch<AuthPayload>(
'/auth/demo',
{
method: 'POST',
},
false,
);
window.localStorage.setItem(tokenStorageKey, payload.token);
window.localStorage.setItem(profileStorageKey, payload.activeProfileId);
setToken(payload.token);
setLoginForm({ email: '', password: '' });
} catch (loginError) {
setError(loginError instanceof Error ? loginError.message : 'Unable to sign in to demo account');
} finally {
setSaving(false);
}
};
const handleLogout = async () => {
try {
await apiFetch('/auth/logout', { method: 'POST' });
@@ -858,6 +884,11 @@ export default function Home() {
<button className="primary-button" disabled={saving} onClick={() => void handleLogin()} type="button">
Sign in
</button>
{allowDemoAccount ? (
<button className="secondary-button" disabled={saving} onClick={() => void handleDemoLogin()} type="button">
Use demo account
</button>
) : null}
</div>
) : allowRegistration ? (
<div className="form-stack">
@@ -883,6 +914,10 @@ export default function Home() {
<p className="muted-copy">Account registration is disabled.</p>
) : null}
{allowDemoAccount ? (
<p className="muted-copy">Demo mode is enabled for quick access.</p>
) : null}
<div className="auth-divider">
<span>Single sign-on</span>
</div>