I m trying to make a nextjs website and im using provider in that but my provider is showing null al the time i tried to debug it with the help of bard and chatgpt but was helpless.
This is my Nav.jsx code and in this i have error with provider,the provider is null can someone tell me the reason
"use client";
import Link from "next/link";
import Image from "next/image";
import { useEffect, useState } from "react";
import { signIn, signOut, useSession, getProviders } from "next-auth/react";
const Nav = () => {
const { data: session } = useSession();
const [providers, setProviders] = useState();
const [toggleDropdown, setToggleDropdown] = useState(false);
useEffect(() => {
(async () => {
const res = await getProviders();
setProviders(res);
})();
}, []);
return (
<nav className='flex-between w-full mb-16 pt-3'>
<Link href='/' className='flex gap-2 flex-center'>
<Image
src='/assets/images/logo.svg'
alt='logo'
width={30}
height={30}
className='object-contain'
/>
<p className='logo_text'>Promptopia</p>
</Link>
{/* Desktop Navigation */}
<div className='sm:flex hidden'>
{session?.user ? (
<div className='flex gap-3 md:gap-5'>
<Link href='/create-prompt' className='black_btn'>
Create Post
</Link>
<button type='button' onClick={signOut} className='outline_btn'>
Sign Out
</button>
<Link href='/profile'>
<Image
src={session?.user.image}
width={37}
height={37}
className='rounded-full'
alt='profile'
/>
</Link>
</div>
) : (
<>
{providers &&
Object.values(providers).map((provider) => (
<button
type='button'
key={provider.name}
onClick={() => {
signIn(provider.id);
}}
className='black_btn'
>
Sign in
</button>
))}
</>
)}
</div>
{/* Mobile Navigation */}
<div className='sm:hidden flex relative'>
{session?.user ? (
<div className='flex'>
<Image
src={session?.user.image}
width={37}
height={37}
className='rounded-full'
alt='profile'
onClick={() => setToggleDropdown(!toggleDropdown)}
/>
{toggleDropdown && (
<div className='dropdown'>
<Link
href='/profile'
className='dropdown_link'
onClick={() => setToggleDropdown(false)}
>
My Profile
</Link>
<Link
href='/create-prompt'
className='dropdown_link'
onClick={() => setToggleDropdown(false)}
>
Create Prompt
</Link>
<button
type='button'
onClick={() => {
setToggleDropdown(false);
signOut();
}}
className='mt-5 w-full black_btn'
>
Sign Out
</button>
</div>
)}
</div>
) : (
<>
{providers &&
Object.values(providers).map((provider) => (
<button
type='button'
key={provider.name}
onClick={() => {
signIn(provider.id);
}}
className='black_btn'
>
Sign in
</button>
))}
</>
)}
</div>
</nav>
);
};
export default Nav;
Want to know why provider is null and want to get it fixed