ai improvements

This commit is contained in:
overcuriousity
2025-07-16 21:33:54 +02:00
parent 89f45b85be
commit 74f28f4fd9
4 changed files with 32 additions and 14 deletions

View File

@@ -374,10 +374,16 @@ async function checkAuthentication() {
try {
const response = await fetch('/api/auth/status');
const data = await response.json();
return data.authenticated;
return {
authenticated: data.authenticated,
authRequired: data.authRequired
};
} catch (error) {
console.error('Auth check failed:', error);
return false;
return {
authenticated: false,
authRequired: true
};
}
}
@@ -409,9 +415,9 @@ document.addEventListener('DOMContentLoaded', () => {
}
// Check authentication
const isAuthenticated = await checkAuthentication();
if (!isAuthenticated) {
// Redirect to login
const authStatus = await checkAuthentication();
if (authStatus.authRequired && !authStatus.authenticated) {
// Redirect to login only if authentication is required
window.location.href = `/api/auth/login?returnTo=${encodeURIComponent(window.location.pathname)}`;
return;
}

View File

@@ -156,8 +156,11 @@ const sortedTags = Object.entries(tagFrequency)
const response = await fetch('/api/auth/status');
const data = await response.json();
if (data.authenticated && aiViewToggle) {
aiViewToggle.style.display = 'inline-flex';
// Show AI button if authentication is not required OR if user is authenticated
if (!data.authRequired || data.authenticated) {
if (aiViewToggle) {
aiViewToggle.style.display = 'inline-flex';
}
}
} catch (error) {
console.log('Auth check failed, AI button remains hidden');