Next.js Discord

Discord Forum

Minor redirect error in auth functions, doesn't crash app but slows loading

Unanswered
Hunting wasp posted this in #help-forum
Open in Discord
Avatar
Hunting waspOP
Hi, I'm not too worried about this issue at this exact point in time as it doesn't get in the way of too much, but it's a bug that I don't want to have follow me into production.

I'm working on auth session management via an ASP.NET backend built by one of my teammates, and while everything works, there's a small error in NEXT_REDIRECT that I get in the browser console, and nowhere else.

This is the function I wrote for checking the session:
export async function checkSession(){
    const response = await fetch("https://localhost:7228/User/Me", {
        method: 'GET',
        credentials: 'include',
        headers:{
            'Accept': '*/*'
        }
    })

    if (!response.ok){
        redirect('/')
    }
}

As I said, it works fine, all that happens is that it's mildly slowed down by the console error in the screencap. I'd like to make sure I'm not pushing anything that might bite me in the ass later, and if there's any way to get around it, that would make my life much easier.
Image

2 Replies

Avatar
Southeastern blueberry bee
hi you cant use redirect() inside client component prefer this instead:
ts 
import { useRouter } from 'next/navigation'
const router = useRouter()
router.push("/")
i mean it can but only during the rendering