'use server'
//import signIn  from "next-auth/react";
import {signIn} from '../../auth'
import http from '../components/http'
 
export const CredentialLogin = async ( formData) =>{
   // console.log(formData)
    const {email,password} = formData
   // console.log(email, password)
  try {
    const status = await signIn('credentials', {
        redirect: false,
        email: email,
        password: password});
        console.log(status)
        return status
        
  } catch (error) {
    if (error) {
      console.log(error)
      switch (error.type) {
        case 'CredentialsSignin':
          return 'Invalid credentials.'
        default:
          return 'Something went wrong.'
      }
    }
    throw error
  }
}

export const register= async ( formData) =>{
    const {email, password, username} =formData
  try {
    const res = await http.post('auth/register', {
      email, password, username, firm:"nil",role:"user"
    })
        console.log(res);
        return res;
        
  } catch (error) {
    if (error) {
      console.log(error)
      switch (error.type) {
        case 'CredentialsSignin':
          return 'Invalid credentials.'
        default:
          return 'Something Went Wrong.'
      }
    }
    throw error
  }
}