auth system consolidation
This commit is contained in:
@@ -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>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user