wwf
3 天以前 a430284aa21e3ae1f0d5654e55b2ad2852519cc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { useTranslation } from 'react-i18next'
import { useSearchParams } from 'next/navigation'
import style from '../page.module.css'
import Button from '@/app/components/base/button'
import { apiPrefix } from '@/config'
import classNames from '@/utils/classnames'
import { getPurifyHref } from '@/utils'
 
type SocialAuthProps = {
  disabled?: boolean
}
 
export default function SocialAuth(props: SocialAuthProps) {
  const { t } = useTranslation()
  const searchParams = useSearchParams()
 
  const getOAuthLink = (href: string) => {
    const url = getPurifyHref(`${apiPrefix}${href}`)
    if (searchParams.has('invite_token'))
      return `${url}?${searchParams.toString()}`
 
    return url
  }
  return <>
    <div className='w-full'>
      <a href={getOAuthLink('/oauth/login/github')}>
        <Button
          disabled={props.disabled}
          className='w-full'
        >
          <>
            <span className={
              classNames(
                style.githubIcon,
                'w-5 h-5 mr-2',
              )
            } />
            <span className="truncate">{t('login.withGitHub')}</span>
          </>
        </Button>
      </a>
    </div>
    <div className='w-full'>
      <a href={getOAuthLink('/oauth/login/google')}>
        <Button
          disabled={props.disabled}
          className='w-full'
        >
          <>
            <span className={
              classNames(
                style.googleIcon,
                'w-5 h-5 mr-2',
              )
            } />
            <span className="truncate">{t('login.withGoogle')}</span>
          </>
        </Button>
      </a>
    </div>
  </>
}