// API file that handles all supertokens auth routes
import { createFileRoute } from '@tanstack/react-router';
import { handleAuthAPIRequest } from 'supertokens-node/custom'
import { ensureSuperTokensBackend } from '@/lib/supertokens/server'

ensureSuperTokensBackend();

// forwards all supertokens api methods to our API
const superTokensHandler = handleAuthAPIRequest();
const handleRequest = async ({ request }: {request: Request}) => {
  console.log("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
  console.log("Handling auth request:", request.method, request.url);
  return superTokensHandler(request);
};
export const Route = createFileRoute('/api/auth/$')({
  server: {
    handlers: {
      GET: handleRequest,
      POST: handleRequest,
      PUT: handleRequest,
      DELETE: handleRequest,
      PATCH: handleRequest,
      OPTIONS: handleRequest,
      HEAD: handleRequest,
    }
  }
})
