social-auth.tsx 1.6 KB

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