Fix login redirect - use server-side redirect instead of redirect:false

The signIn with redirect:false + router.push wasn't working
properly. Switched to callbackUrl approach where the server
handles the 302 redirect and cookie setting natively.
This commit is contained in:
2026-05-30 15:41:59 +01:00
parent 816c1c40c6
commit 661d053ea0
2 changed files with 19 additions and 15 deletions

7
cookies.txt Normal file
View File

@@ -0,0 +1,7 @@
# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
#HttpOnly_localhost FALSE / FALSE 1782744103 next-auth.session-token eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..sTq2NT-4CyoN9xHf.XbycUv1magKQZIOpnjRtViV-R7kDNoAmG9uHcvK6Yx0_jJxcOhPp8_Or5XinQtMTYDoMSGsoR5aTt1zkH8RB1d6D9s-7fE7eMMt8YxCs7WTTaP_ES6aDWH06w7B8IiSWlnqAYi5Qs1KVAYWHLMBLMsU04n5qA6YttlYxTW_cBBdLR8C_UPa9NwNJxVtcXVfgOtWdosoc8x88Two39U9ylQ3vNkTVbEFO1o3o1QB2MpPboWcvzUPnYGgaYXQ2z3uGbInIeIJTB6QYVfqPeSdyroP-uSGh2cT_.zSa0swhlkozNLXOuC6QFTA
#HttpOnly_localhost FALSE / FALSE 0 next-auth.csrf-token 69bf7c3ba6e09540208c60c74bee0e63213544d508e4b4e4e33541160efe2dae%7C6130062784bd8a3d2ef18b88eb8c23a689728bbbdfebe0d9a316044c1229365a
#HttpOnly_localhost FALSE / FALSE 0 next-auth.callback-url http%3A%2F%2Flocalhost%3A3000

View File

@@ -1,8 +1,8 @@
'use client'
import { useState } from 'react'
import { useState, useEffect } from 'react'
import { signIn } from 'next-auth/react'
import { useRouter } from 'next/navigation'
import { useSearchParams } from 'next/navigation'
import { Eye } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
@@ -10,32 +10,29 @@ import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
export default function LoginPage() {
const router = useRouter()
const searchParams = useSearchParams()
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const [loading, setLoading] = useState(false)
useEffect(() => {
const err = searchParams.get('error')
if (err === 'CredentialsSignin') {
setError('Email ou mot de passe incorrect')
}
}, [searchParams])
async function handleSubmit(e: React.FormEvent) {
e.preventDefault()
setError('')
setLoading(true)
const result = await signIn('credentials', {
await signIn('credentials', {
email,
password,
redirect: false,
callbackUrl: '/',
})
setLoading(false)
if (result?.error) {
setError('Email ou mot de passe incorrect')
return
}
router.push('/')
router.refresh()
}
return (