TS7006: Parameter credentials implicitly has an any type.
TS2322: Type
{   id: string;   name: string;   type: string;   credentials: {    phoneNumber: {     label: string;     type: string;    };    otp: {     label: string;     type: string;    };   };   authorize: (credentials: any) => Promise<any>; }
is not assignable to type Provider
Type '{ id: string; name: string; type: string; credentials: { phoneNumber: { label: string; type: string; }; otp: { label: string; type: string; }; }; authorize: (credentials: any) => Promise<any>; }' is not assignable to type 'CredentialsConfig<Record<string, CredentialInput>> & InternalProviderOptions'.
Type '{ id: string; name: string; type: string; credentials: { phoneNumber: { label: string; type: string; }; otp: { label: string; type: string; }; }; authorize: (credentials: any) => Promise<any>; }' is not assignable to type 'CredentialsConfig<Record<string, CredentialInput>>'.
Types of property type are incompatible.
Type string is not assignable to type "credentials"
import NextAuth from "next-auth";
import axios from "axios";

const SMSOTPProvider = {
  id: "sms-otp",
  name: "SMS OTP",
  type: "credentials",
  credentials: {
    phoneNumber: { label: "Phone Number", type: "tel" },
    otp: { label: "OTP", type: "text" },
  },
  authorize: async (credentials) => {
    try {
      console.log("Authorize function called with credentials:", credentials);

      const { phoneNumber, otp } = credentials;

      console.log("Parsed credentials:", { phoneNumber, otp });

      // Verify OTP
      const isValid = await verifyOTP(phoneNumber, otp);

      console.log("OTP verification result:", isValid);

      if (isValid) {
        // Fetch or create user based on phone number
        const user = await getUserByPhoneNumber(phoneNumber);
        console.log("User retrieved:", user);
        return user;
      }

      console.log("OTP verification failed");
      return null;
    } catch (error) {
      console.error("Error in authorize function:", error);
      throw error;
    }
  },
};

export const { handlers, auth } = NextAuth({
  providers: [SMSOTPProvider],
  debug: true, // Enable debug mode for more detailed logs
});

async function generateOTP(phoneNumber: string): Promise<boolean> {
  try {
    const response = await axios.post(
      "https://api.bimehtakmili.com/api/login/generate_token",
      {
        mobile_no: phoneNumber,
      },
      {
        headers: {
          "Content-Type": "application/json",
          accept: "application/json",
        },
      },
    );

    return response.status === 200;
  } catch (error) {
    console.error("Error generating OTP:", error);
    return false;
  }
}

async function verifyOTP(phoneNumber: string, otp: string): Promise<boolean> {
  try {
    const response = await axios.post(
      "https://api.bimehtakmili.com/api/login/verify_otp",
      {
        mobile_no: phoneNumber,
        otp: otp,
      },
      {
        headers: {
          "Content-Type": "application/json",
          accept: "application/json",
        },
      },
    );

    return response.status === 200;
  } catch (error) {
    console.error("Error verifying OTP:", error);
    return false;
  }
}

async function getUserByPhoneNumber(phoneNumber: string): Promise<any> {
  // Implement logic to fetch or create a user based on the phone number
  // Return user object if found/created, null otherwise
  // For now, let's return a mock user
  return {
    id: "1",
    phoneNumber: phoneNumber,
    name: "Test User",
  };
}