import * as React from "react";
import type { ActionFunction, LoaderFunction, MetaFunction } from "remix";
import {
  Form,
  json,
  Link,
  useActionData,
  redirect,
  useSearchParams,
} from "remix";
import { discordLogin } from "~/discord";

import { createUserSession, getUserId } from "~/session.server";

export const loader: LoaderFunction = async ({ request }) => {
  const userId = await getUserId(request);
  if (userId) return redirect("/");

  const url = new URL(await request.url);
  const accessCode = url.searchParams.get("code") || "";

  const response = await discordLogin(request, accessCode);
  console.log(response);
  return ""
};

export const meta: MetaFunction = () => {
  return {
    title: "Login",
  };
};

export default function LoginPage() {
  return (
    <div className="flex min-h-full flex-col justify-center">
      <p>Error logging in.</p>  
    </div>
  )
}
