import Discord from "@auth/core/providers/discord";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import { type SolidAuthConfig } from "@auth/solid-start";
import db from "~/drizzle";

export const authOptions: SolidAuthConfig = {
  providers: [
    {
      ...Discord({
        clientId: import.meta.env.VITE_DISCORD_CLIENT_ID,
        clientSecret: import.meta.env.VITE_DISCORD_CLIENT_SECRET,
      }),
      authorization:
        "https://discord.com/api/oauth2/authorize?scope=identify+email+guilds+guilds.members.read",
    },
  ],
  adapter: DrizzleAdapter(db),
  secret: import.meta.env.VITE_AUTH_SECRET,
  callbacks: {
    // @ts-ignore
    session: ({ session, user }) => {
      if (session?.user) {
        session.user.id = user.id;
      }
      return session;
    },
  },
  pages: {
    // signIn: "/signin",
    // signOut: "/signout",
    // error: '/auth/error', // Error code passed in query string as ?error=
    // verifyRequest: '/auth/verify-request', // (used for check email message)
    // newUser: '/auth/new-user' // New users will be directed here on first sign in (leave the property out if not of interest)
  },
  redirectProxyUrl: import.meta.env.DEV
    ? import.meta.env.VITE_AUTH_REDIRECT_PROXY_URL
    : undefined,
};
