ai improvements
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user