auth system consolidation

This commit is contained in:
overcuriousity
2025-07-24 20:40:17 +02:00
parent 209f173d7a
commit 1f33ad1b16
4 changed files with 15 additions and 69 deletions

View File

@@ -1,5 +1,5 @@
---
// src/components/ContributionButton.astro
// src/components/ContributionButton.astro - CLEANED: Removed duplicate auth script
export interface Props {
type: 'edit' | 'new' | 'write';
toolName?: string;
@@ -69,33 +69,4 @@ const iconSize = variant === 'small' ? '14' : '16';
<Fragment set:html={icon} />
</svg>
{displayText}
</a>
<script>
// Check authentication status and redirect if needed
document.addEventListener('DOMContentLoaded', () => {
const contributeButtons = document.querySelectorAll('[data-contribute-button]');
contributeButtons.forEach(button => {
button.addEventListener('click', async (e) => {
e.preventDefault();
try {
const response = await fetch('/api/auth/status');
const data = await response.json();
if (data.authRequired && !data.authenticated) {
const returnUrl = (button as HTMLAnchorElement).href;
window.location.href = `/api/auth/login?returnTo=${encodeURIComponent(returnUrl)}`;
} else {
window.location.href = (button as HTMLAnchorElement).href;
}
} catch (error) {
console.error('Auth check failed:', error);
// Fallback - proceed anyway
window.location.href = (button as HTMLAnchorElement).href;
}
});
});
});
</script>
</a>

View File

@@ -852,32 +852,5 @@ domains.forEach((domain: any) => {
}
}
});
document.addEventListener('DOMContentLoaded', () => {
// Auth check for contribution buttons (similar to existing auth checking pattern)
function setupContributionButtonAuth() {
document.addEventListener('click', async (e) => {
const contributeButton = e.target.closest('[data-contribute-button]');
if (!contributeButton) return;
e.preventDefault();
try {
const response = await fetch('/api/auth/status');
const data = await response.json();
if (data.authRequired && !data.authenticated) {
const returnUrl = contributeButton.href;
window.location.href = `/api/auth/login?returnTo=${encodeURIComponent(returnUrl)}`;
} else {
window.location.href = contributeButton.href;
}
} catch (error) {
console.error('Auth check failed:', error);
window.location.href = contributeButton.href;
}
});
}
setupContributionButtonAuth();
});
</script>