Login Error and Message
This commit is contained in:
parent
9de0296169
commit
336986272a
4 changed files with 73 additions and 35 deletions
|
|
@ -25,7 +25,7 @@ const Side = ({ children, content, ...rest }: SideProps) => {
|
|||
<Avatar className="border-2 border-white" shape="circle" src="/img/others/cto.png" />
|
||||
<div className="text-white">
|
||||
<div className="font-semibold text-base">Sedat ÖZTÜRK</div>
|
||||
<span className="opacity-80">CTO</span>
|
||||
<span className="opacity-80">Founder</span>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-lg text-white opacity-80">
|
||||
|
|
|
|||
|
|
@ -14,9 +14,12 @@ let didInit = false
|
|||
const Theme = (props: CommonProps) => {
|
||||
// ABP App Config'i uygulama acilirken al
|
||||
const { getConfig } = useStoreActions((a) => a.abpConfig)
|
||||
const { setTenantId } = useStoreActions((a) => a.auth)
|
||||
|
||||
useEffect(() => {
|
||||
if (!didInit) {
|
||||
didInit = true
|
||||
setTenantId('')
|
||||
getConfig(false)
|
||||
}
|
||||
}, [])
|
||||
|
|
|
|||
|
|
@ -7,16 +7,39 @@ const authApiService = axios.create({
|
|||
baseURL: appConfig.baseUrl,
|
||||
})
|
||||
|
||||
function extractTitle(html: string): string {
|
||||
const match = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i)
|
||||
return match ? match[1].replace(/<[^>]+>/g, '').trim() : html
|
||||
}
|
||||
|
||||
function extractBody(html: string): string {
|
||||
const match = html.match(/<body[^>]*>([\s\S]*?)<\/body>/i)
|
||||
return match ? match[1].replace(/<[^>]+>/g, '').trim() : html
|
||||
}
|
||||
|
||||
authApiService.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error) => {
|
||||
console.log('Error interceptor')
|
||||
console.error(error)
|
||||
//console.log('Error interceptor')
|
||||
//console.error(error)
|
||||
const { messages } = store.getActions().base
|
||||
let rawTitle = 'Hata!'
|
||||
let rawMessage =
|
||||
error.response?.data?.error_description ||
|
||||
error.response?.data?.error?.message ||
|
||||
error.response?.data?.message ||
|
||||
error.message ||
|
||||
'Bir hata oluştu'
|
||||
|
||||
if (error.response?.status === 404 && typeof error.response?.data === 'string') {
|
||||
rawMessage = extractBody(error.response.data)
|
||||
rawTitle = extractTitle(error.response.data)
|
||||
}
|
||||
|
||||
messages.addError({
|
||||
id: crypto.randomUUID(),
|
||||
message: error.response?.data?.error?.message ?? error.message ?? 'Bir hata oluştu',
|
||||
title: 'Hata!',
|
||||
message: rawMessage, //error.response?.data?.error?.message ?? error.message ?? 'Bir hata oluştu',
|
||||
title: rawTitle,
|
||||
cid: error.response?.headers['x-correlation-id'],
|
||||
statusCode: error.response?.status?.toString() ?? error.code,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -60,8 +60,6 @@ const Login = () => {
|
|||
}, 100)
|
||||
}
|
||||
|
||||
const [tenantList, setTenantList] = useState<{ value?: string; label?: string }[]>([])
|
||||
|
||||
const { signIn } = useAuth()
|
||||
const { translate } = useLocalization()
|
||||
|
||||
|
|
@ -171,20 +169,27 @@ const Login = () => {
|
|||
setSubmitting(false)
|
||||
}
|
||||
|
||||
const fetchData = async () => {
|
||||
const response = await getTenants(0, 1000)
|
||||
if (response.data?.items) {
|
||||
setTenantList(response.data.items.map((a) => ({ value: a.id, label: a.name })))
|
||||
const subDomainName = getSubdomain()
|
||||
//const subDomainName = 'DEMO2'
|
||||
const tenantId = useStoreState((a) => a.auth.tenantId) ?? subDomainName
|
||||
const tenantStyle: React.CSSProperties | undefined =
|
||||
subDomainName && subDomainName !== 'DEMO'
|
||||
? {
|
||||
opacity: 0,
|
||||
position: 'absolute',
|
||||
pointerEvents: 'none',
|
||||
height: 0,
|
||||
margin: 0,
|
||||
padding: 0,
|
||||
border: 'none',
|
||||
}
|
||||
}
|
||||
|
||||
const tenantId = useStoreState((a) => a.auth.tenantId) ?? getSubdomain()
|
||||
: undefined
|
||||
|
||||
useEffect(() => {
|
||||
if (!isMultiTenant) {
|
||||
return
|
||||
}
|
||||
fetchData()
|
||||
setTenantId(subDomainName || '')
|
||||
}, [isMultiTenant])
|
||||
|
||||
return (
|
||||
|
|
@ -198,27 +203,22 @@ const Login = () => {
|
|||
<p>Please enter your credentials to sign in!</p>
|
||||
</div>
|
||||
{isMultiTenant && (
|
||||
<>
|
||||
<label className="form-label mb-2" style={tenantStyle}>
|
||||
Company
|
||||
</label>
|
||||
<div className="mb-4">
|
||||
<Select
|
||||
<Input
|
||||
placeholder={translate('::Sirket')}
|
||||
isClearable={true}
|
||||
options={tenantList}
|
||||
value={tenantList.find((a) => a.value == tenantId)}
|
||||
onChange={(option) => setTenantId(option?.value)}
|
||||
value={tenantId || ''}
|
||||
onChange={(e) => setTenantId(e.target.value)}
|
||||
style={tenantStyle}
|
||||
aria-hidden={subDomainName && subDomainName !== 'DEMO' ? 'true' : 'false'}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div>
|
||||
{message && (
|
||||
<Alert showIcon className="mb-4" type="success">
|
||||
{message}
|
||||
</Alert>
|
||||
)}
|
||||
{error && (
|
||||
<Alert showIcon className="mb-4" type="danger">
|
||||
{error}
|
||||
</Alert>
|
||||
)}
|
||||
<Formik
|
||||
initialValues={{
|
||||
userName: '',
|
||||
|
|
@ -291,6 +291,18 @@ const Login = () => {
|
|||
onSuccess={(token: string) => setFieldValue('captchaResponse', token)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{message && (
|
||||
<Alert showIcon className="mb-4" type="success">
|
||||
{message}
|
||||
</Alert>
|
||||
)}
|
||||
{error && (
|
||||
<Alert showIcon className="mb-4" type="danger">
|
||||
{error}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Button block loading={isSubmitting} variant="solid" type="submit">
|
||||
{isSubmitting ? 'Signing in...' : 'Sign In'}
|
||||
</Button>
|
||||
|
|
|
|||
Loading…
Reference in a new issue