Files
bolt.diy/app/routes/api.auth.status.ts
Nirmal Arya c255d00973 fix: replace @remix-run/node imports with @remix-run/cloudflare for compatibility
- Update all auth-related routes to use @remix-run/cloudflare imports
- Fix GitHub OAuth server utilities to use Cloudflare-compatible session storage
- Resolve build failures caused by Node.js-specific modules in browser bundle
- Enable successful production builds for EKS deployment

This resolves the 'Cannot access xs before initialization' error by ensuring all imports are compatible with the Cloudflare Workers runtime environment.
2025-05-31 16:07:44 -04:00

58 lines
1.4 KiB
TypeScript

import { json, type LoaderFunctionArgs } from '@remix-run/cloudflare';
import {
getUserFromSession,
isAuthenticated,
getAccessToken,
} from '~/lib/auth/github-oauth.server';
/**
* API route to check authentication status
* Used by the client to sync authentication state between server and client
*/
export async function loader({ request }: LoaderFunctionArgs) {
// Only allow GET requests
if (request.method !== 'GET') {
return json(
{ error: 'Method not allowed' },
{ status: 405, headers: { 'Allow': 'GET' } }
);
}
try {
// Check if user is authenticated
const authenticated = await isAuthenticated(request);
if (!authenticated) {
// Return unauthenticated status
return json({ isAuthenticated: false });
}
// Get user data from session
const user = await getUserFromSession(request);
// Get current access token
const accessToken = await getAccessToken(request);
// Build response
return json({
isAuthenticated: true,
user,
// Don't expose the actual token to the client
tokenStatus: {
hasToken: Boolean(accessToken),
},
});
} catch (error) {
console.error('Error checking authentication status:', error);
// Return error response
return json(
{
isAuthenticated: false,
error: 'Failed to check authentication status'
},
{ status: 500 }
);
}
}