Next navigation/redirect error
Answered
Doberman Pinscher posted this in #help-forum
Doberman PinscherOP
whenever i submit my form i get an error
Unhandled Runtime Error
Error: NEXT_REDIRECT
Unhandled Runtime Error
Error: NEXT_REDIRECT
const onSubmit = async (credentials: UserLoginType) => {
const loginToast = toast.loading('ÐвторизациÑ...')
const response = await fetch('/api/auth/login', {
method: 'POST',
body: JSON.stringify({
email: credentials.email,
password: credentials.password,
}),
headers: { 'Content-Type': 'application/json' },
})
const result = await response.json()
console.log(result)
if (!response.ok) {
toast.update(loginToast, {
render: result.detail,
type: 'error',
isLoading: false,
autoClose: 3000,
})
return null
}
toast.update(loginToast, {
render: result.message,
type: 'success',
isLoading: false,
autoClose: 3000,
})
redirect('/')
}3 Replies
You can’t use redirect in client components, consider using
router.push instead.const router = useRouter()
router.push(“/pathâ€)Answer
@fuma You can’t use redirect in client components, consider using `router.push` instead.
Doberman PinscherOP
thank you