this is my next js index file. Here i have used next-auth version 4 library.
import React from 'react'
import { useRouter } from 'next/router'
import { useSession } from 'next-auth/react'
import { Login } from '@/components/Login/Login'
export default function Home() {
const router = useRouter()
const callbackUrl = (router.query?.callbackUrl as string) ?? '/dashboard'
const { data: session, status } = useSession()
const loading = status === 'loading'
if (!loading && !session) {
return <Login />
}
if (session) {
router.push(callbackUrl)
}
}
I have passed a custom login page for the sigin. It was achieved by setting the page inside [...nextauth].ts file
pages: {
signIn: '/'
}
Above custom login page contain below button with an onclick event for the sign in.
<Button
onClick={(e) => {
e.preventDefault()
signIn('cognito', { redirect: false })
}}
appearance={appearance}
style={{ fontWeight: 'bold' }}
>
But after the sign in, it's correctly redirected to the requested page, but there is an error in the console:
Error: Abort fetching component for route: "/settings"
How to fix this issue?