import type { LoaderFunction, MetaFunction } from "remix";
import {
  json,
  redirect,
} from "remix";
import { getUserId } from "~/session.server";

export const loader: LoaderFunction = async ({ request }) => {
  const userId = await getUserId(request);
  if (userId) return redirect("/");
  const client_id = process.env.DISCORD_CLIENT_ID || "";
  const redirect_uri = process.env.DISCORD_REDIRECT_URI || "";
  return redirect(`https://discord.com/api/oauth2/authorize?client_id=${client_id}` +
  `&response_type=code&redirect_uri=${encodeURIComponent(redirect_uri)}&scope=identify`);
};

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

export default function LoginPage() {
  return <div></div>
}
