import { Authenticator } from "remix-auth";
import { FormStrategy } from "remix-auth-form";
import { sessionStorage } from "./sessions.server";

export const authenticator = new Authenticator(sessionStorage);

// login
authenticator.use(
  new FormStrategy(async ({ form }) => {
    const phoneNumber = form.get("phoneNumber") as string;
    const access_token = form.get("access_token") as string;
    const refresh_token = form.get("refresh_token") as string;
    return {
      phoneNumber: phoneNumber?.toString(),
      access_token: access_token?.toString(),
      refresh_token: refresh_token?.toString(),
      loggedIn: true,
    };
  }),
  "vitrown-login"
);
