enhance: helpful error message on login (#2094)

* enhance: helpful error message on login

* better message, don't edit original message

* fix comment placement
This commit is contained in:
soxa 2025-04-12 21:23:08 +02:00 committed by GitHub
parent 34c02ece88
commit bc0be4f92a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,6 +12,7 @@ import { OverlayTrigger, Tooltip } from 'react-bootstrap'
import { datePivot } from '@/lib/time'
import * as cookie from 'cookie'
import { cookieOptions } from '@/lib/auth'
import Link from 'next/link'
export function EmailLoginForm ({ text, callbackUrl, multiAuth }) {
const disabled = multiAuth
@ -52,12 +53,26 @@ const authErrorMessages = {
default: 'Auth failed. Try again or choose a different method.'
}
export function authErrorMessage (error) {
return error && (authErrorMessages[error] ?? authErrorMessages.default)
export function authErrorMessage (error, signin) {
if (!error) return null
const message = error && (authErrorMessages[error] ?? authErrorMessages.default)
// workaround for signin/signup awareness due to missing support from next-auth
if (signin) {
return (
<>
{message}
<br />
If you are new to Stacker News, please <Link className='fw-bold' href='/signup'>sign up</Link> first.
</>
)
}
return message
}
export default function Login ({ providers, callbackUrl, multiAuth, error, text, Header, Footer, signin }) {
const [errorMessage, setErrorMessage] = useState(authErrorMessage(error))
const [errorMessage, setErrorMessage] = useState(authErrorMessage(error, signin))
const router = useRouter()
// signup/signin awareness cookie