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:
parent
34c02ece88
commit
bc0be4f92a
@ -12,6 +12,7 @@ import { OverlayTrigger, Tooltip } from 'react-bootstrap'
|
|||||||
import { datePivot } from '@/lib/time'
|
import { datePivot } from '@/lib/time'
|
||||||
import * as cookie from 'cookie'
|
import * as cookie from 'cookie'
|
||||||
import { cookieOptions } from '@/lib/auth'
|
import { cookieOptions } from '@/lib/auth'
|
||||||
|
import Link from 'next/link'
|
||||||
|
|
||||||
export function EmailLoginForm ({ text, callbackUrl, multiAuth }) {
|
export function EmailLoginForm ({ text, callbackUrl, multiAuth }) {
|
||||||
const disabled = multiAuth
|
const disabled = multiAuth
|
||||||
@ -52,12 +53,26 @@ const authErrorMessages = {
|
|||||||
default: 'Auth failed. Try again or choose a different method.'
|
default: 'Auth failed. Try again or choose a different method.'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function authErrorMessage (error) {
|
export function authErrorMessage (error, signin) {
|
||||||
return error && (authErrorMessages[error] ?? authErrorMessages.default)
|
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 }) {
|
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()
|
const router = useRouter()
|
||||||
|
|
||||||
// signup/signin awareness cookie
|
// signup/signin awareness cookie
|
||||||
|
Loading…
x
Reference in New Issue
Block a user