'use client' import { useState, FC, useEffect } from "react" import Link from "next/link" import { Form, Input } from "antd" import { signIn, useSession } from "next-auth/react"; import { useRouter, useSearchParams } from "next/navigation" import { Icons } from "@/components/Icons" import { Button } from "@/components/ui/button" import { Label } from "@/components/ui/label" import { ToggleTheme } from '@/components/ToggleTheme'; import ForgotPassword from "../(dashboard)/profile/components/ForgotPassword"; import Logo from "../(dashboard)/components/Logo"; import { toast } from "sonner"; type Props = {}; const LoginPage: FC = ({ }) => { const [isLoading, setIsLoading] = useState(false) const { data: session, status } = useSession(); const router = useRouter() const searchParams = useSearchParams(); const error = searchParams!.get('error'); const callbackUrl = searchParams!.get('callbackUrl') useEffect(() => { if (session?.user.access_token && !error) { router.replace(callbackUrl || '/admin') } }, [session, error]) const onFinish = async (values: any) => { console.log('Success:', values); setIsLoading(true) signIn('credentials', { email: values.email, password: values.password, redirect: false, // callbackUrl: callbackUrl || '/admin' }).then(res => { console.log(res) if (!res?.ok) { toast.error("Oops! Something went wrong.", { description: `(${res?.status}) ${res?.error}`, }) setIsLoading(false) } else { console.log("NEXTAUTH LOGIN :", res) // router.replace(callbackUrl || '/admin') window.location.href = callbackUrl || '/admin' } }).catch(err => { console.log(err) toast.error("Oops! Something went wrong.", { description: err.message as string, }) setIsLoading(false) }) }; return ( <>
{error &&
{error}
}

Login an account

Welcome back, sign in to continue access

Forgot Password ?

By clicking continue, you agree to our{" "} Terms of Service {" "} and{" "} Privacy Policy .

); } export default LoginPage;