mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-10 03:16:51 +08:00
Remove useless code (#4416)
This commit is contained in:
87
web/app/signin/userSSOForm.tsx
Normal file
87
web/app/signin/userSSOForm.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
'use client'
|
||||
import cn from 'classnames'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
import type { FC } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
import { getUserOIDCSSOUrl, getUserSAMLSSOUrl } from '@/service/sso'
|
||||
import Button from '@/app/components/base/button'
|
||||
|
||||
type UserSSOFormProps = {
|
||||
protocol: string
|
||||
}
|
||||
|
||||
const UserSSOForm: FC<UserSSOFormProps> = ({
|
||||
protocol,
|
||||
}) => {
|
||||
const searchParams = useSearchParams()
|
||||
const consoleToken = searchParams.get('console_token')
|
||||
const message = searchParams.get('message')
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (consoleToken) {
|
||||
localStorage.setItem('console_token', consoleToken)
|
||||
router.replace('/apps')
|
||||
}
|
||||
|
||||
if (message) {
|
||||
Toast.notify({
|
||||
type: 'error',
|
||||
message,
|
||||
})
|
||||
}
|
||||
}, [])
|
||||
|
||||
const handleSSOLogin = () => {
|
||||
setIsLoading(true)
|
||||
if (protocol === 'saml') {
|
||||
getUserSAMLSSOUrl().then((res) => {
|
||||
router.push(res.url)
|
||||
}).finally(() => {
|
||||
setIsLoading(false)
|
||||
})
|
||||
}
|
||||
else {
|
||||
getUserOIDCSSOUrl().then((res) => {
|
||||
document.cookie = `user-oidc-state=${res.state}`
|
||||
router.push(res.url)
|
||||
}).finally(() => {
|
||||
setIsLoading(false)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={
|
||||
cn(
|
||||
'flex flex-col items-center w-full grow justify-center',
|
||||
'px-6',
|
||||
'md:px-[108px]',
|
||||
)
|
||||
}>
|
||||
<div className='flex flex-col md:w-[400px]'>
|
||||
<div className="w-full mx-auto">
|
||||
<h2 className="text-[32px] font-bold text-gray-900">{t('login.pageTitle')}</h2>
|
||||
</div>
|
||||
<div className="w-full mx-auto mt-10">
|
||||
<Button
|
||||
tabIndex={0}
|
||||
type='primary'
|
||||
onClick={() => { handleSSOLogin() }}
|
||||
disabled={isLoading}
|
||||
className="w-full !fone-medium !text-sm"
|
||||
>{t('login.sso')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default UserSSOForm
|
||||
Reference in New Issue
Block a user