Files
ALwrity/frontend/src/utils/auth.ts
Om-Singh1808 0a7d9bfd21 feat: Complete Google Search Console integration with Clerk authentication
- Add GSC API service with OAuth2 authentication
- Implement Clerk authentication for frontend and backend
- Add GSC login button and OAuth callback handling
- Create comprehensive GSC data fetching and caching
- Add authentication middleware for backend API protection
- Implement real-time GSC data integration in SEO dashboard
- Add user-specific GSC site management
- Include comprehensive logging and error handling
- Add TypeScript support and proper type definitions
- Create environment templates and setup documentation
- Update gitignore to exclude sensitive credential files

Features added:
- GSC OAuth2 authentication flow
- Real-time search analytics data
- Site list management
- Sitemap analysis
- User-specific data isolation
- Comprehensive error handling
- Authentication token management
- Popup-based OAuth flow
- Data caching and refresh mechanisms

Note: gsc_credentials.json should be created locally with your Google OAuth credentials
2025-09-24 15:12:21 +05:30

37 lines
916 B
TypeScript

/** Authentication utilities for ALwrity frontend. */
import { useAuth } from '@clerk/clerk-react';
/**
* Hook to get the current authentication token
*/
export const useAuthToken = () => {
const { getToken } = useAuth();
const getAuthToken = async (): Promise<string | null> => {
try {
const token = await getToken();
return token;
} catch (error) {
console.error('Error getting auth token:', error);
return null;
}
};
return { getAuthToken };
};
/**
* Get auth token without using hooks (for use in non-React contexts)
* This requires the Clerk instance to be available globally
*/
export const getAuthTokenSync = async (): Promise<string | null> => {
try {
// This is a fallback method - in practice, we'll use the hook version
return null;
} catch (error) {
console.error('Error getting auth token sync:', error);
return null;
}
};