show errors on settings during auth linking
This commit is contained in:
parent
63a4a7acad
commit
42bdd40f91
@ -31,8 +31,7 @@ export function EmailLoginForm ({ text, callbackUrl }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Login ({ providers, callbackUrl, error, text, Header, Footer }) {
|
const authErrorMessages = {
|
||||||
const errors = {
|
|
||||||
OAuthSignin: 'Error constructing OAuth URL. Try again or choose a different method.',
|
OAuthSignin: 'Error constructing OAuth URL. Try again or choose a different method.',
|
||||||
OAuthCallback: 'Error handling OAuth response. Try again or choose a different method.',
|
OAuthCallback: 'Error handling OAuth response. Try again or choose a different method.',
|
||||||
OAuthCreateAccount: 'Could not create OAuth account. Try again or choose a different method.',
|
OAuthCreateAccount: 'Could not create OAuth account. Try again or choose a different method.',
|
||||||
@ -42,9 +41,14 @@ export default function Login ({ providers, callbackUrl, error, text, Header, Fo
|
|||||||
EmailSignin: 'Failed to send email. Make sure you entered your email address correctly.',
|
EmailSignin: 'Failed to send email. Make sure you entered your email address correctly.',
|
||||||
CredentialsSignin: 'Auth failed. Try again or choose a different method.',
|
CredentialsSignin: 'Auth failed. Try again or choose a different method.',
|
||||||
default: 'Auth failed. Try again or choose a different method.'
|
default: 'Auth failed. Try again or choose a different method.'
|
||||||
}
|
}
|
||||||
|
|
||||||
const [errorMessage, setErrorMessage] = useState(error && (errors[error] ?? errors.default))
|
export function authErrorMessage(error) {
|
||||||
|
return error && (authErrorMessages[error] ?? authErrorMessages.default)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Login ({ providers, callbackUrl, error, text, Header, Footer }) {
|
||||||
|
const [errorMessage, setErrorMessage] = useState(authErrorMessage(error))
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
if (router.query.type === 'lightning') {
|
if (router.query.type === 'lightning') {
|
||||||
|
@ -23,6 +23,14 @@ export async function getServerSideProps ({ req, res, query: { callbackUrl, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session && callbackUrl) {
|
if (session && callbackUrl) {
|
||||||
|
// in the cause of auth linking we want to pass the error back to
|
||||||
|
// settings
|
||||||
|
if (error) {
|
||||||
|
const url = new URL(callbackUrl, process.env.PUBLIC_URL)
|
||||||
|
url.searchParams.set('error', error)
|
||||||
|
callbackUrl = url.pathname + url.search
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
destination: callbackUrl,
|
destination: callbackUrl,
|
||||||
|
@ -20,6 +20,7 @@ import { emailSchema, lastAuthRemovalSchema, settingsSchema } from '../lib/valid
|
|||||||
import { SUPPORTED_CURRENCIES } from '../lib/currency'
|
import { SUPPORTED_CURRENCIES } from '../lib/currency'
|
||||||
import PageLoading from '../components/page-loading'
|
import PageLoading from '../components/page-loading'
|
||||||
import { useShowModal } from '../components/modal'
|
import { useShowModal } from '../components/modal'
|
||||||
|
import { authErrorMessage } from '../components/login'
|
||||||
|
|
||||||
export const getServerSideProps = getGetServerSideProps(SETTINGS)
|
export const getServerSideProps = getGetServerSideProps(SETTINGS)
|
||||||
|
|
||||||
@ -330,6 +331,8 @@ function UnlinkObstacle ({ onClose, type, unlinkAuth }) {
|
|||||||
|
|
||||||
function AuthMethods ({ methods }) {
|
function AuthMethods ({ methods }) {
|
||||||
const showModal = useShowModal()
|
const showModal = useShowModal()
|
||||||
|
const router = useRouter()
|
||||||
|
const [err, setErr] = useState(authErrorMessage(router.query.error))
|
||||||
const [unlinkAuth] = useMutation(
|
const [unlinkAuth] = useMutation(
|
||||||
gql`
|
gql`
|
||||||
mutation unlinkAuth($authType: String!) {
|
mutation unlinkAuth($authType: String!) {
|
||||||
@ -369,6 +372,15 @@ function AuthMethods ({ methods }) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className='form-label mt-3'>auth methods</div>
|
<div className='form-label mt-3'>auth methods</div>
|
||||||
|
{err && <Alert variant='danger' onClose={() => {
|
||||||
|
const { pathname, query: { error, nodata, ...rest } } = router
|
||||||
|
router.replace({
|
||||||
|
pathname,
|
||||||
|
query: { nodata, ...rest }
|
||||||
|
}, { pathname, query: { ...rest } }, { shallow: true })
|
||||||
|
setErr(undefined)
|
||||||
|
}} dismissible>{err}</Alert>}
|
||||||
|
|
||||||
{providers?.map(provider => {
|
{providers?.map(provider => {
|
||||||
if (provider === 'email') {
|
if (provider === 'email') {
|
||||||
return methods.email
|
return methods.email
|
||||||
|
Loading…
x
Reference in New Issue
Block a user