|
1 | | -import { notify, Skeleton } from '@affine/component'; |
| 1 | +import { Skeleton } from '@affine/component'; |
2 | 2 | import { Button } from '@affine/component/ui/button'; |
3 | | -import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks'; |
4 | | -import { track } from '@affine/core/mixpanel'; |
5 | | -import { popupWindow } from '@affine/core/utils'; |
6 | | -import { apis } from '@affine/electron-api'; |
7 | 3 | import { OAuthProviderType } from '@affine/graphql'; |
8 | 4 | import { GithubIcon, GoogleDuotoneIcon } from '@blocksuite/icons/rc'; |
9 | 5 | import { useLiveData, useService } from '@toeverything/infra'; |
10 | 6 | import type { ReactElement } from 'react'; |
11 | | -import { useState } from 'react'; |
12 | 7 |
|
13 | | -import { AuthService, ServerConfigService } from '../../../modules/cloud'; |
| 8 | +import { ServerConfigService } from '../../../modules/cloud'; |
14 | 9 |
|
15 | 10 | const OAuthProviderMap: Record< |
16 | 11 | OAuthProviderType, |
@@ -50,39 +45,23 @@ export function OAuth() { |
50 | 45 |
|
51 | 46 | function OAuthProvider({ provider }: { provider: OAuthProviderType }) { |
52 | 47 | const { icon } = OAuthProviderMap[provider]; |
53 | | - const authService = useService(AuthService); |
54 | | - const [isConnecting, setIsConnecting] = useState(false); |
55 | | - |
56 | | - const onClick = useAsyncCallback(async () => { |
57 | | - try { |
58 | | - setIsConnecting(true); |
59 | | - const url = await authService.oauthPreflight(provider); |
60 | | - if (environment.isElectron) { |
61 | | - await apis?.ui.openExternal(url); |
62 | | - } else { |
63 | | - popupWindow(url); |
64 | | - } |
65 | | - } catch (err) { |
66 | | - console.error(err); |
67 | | - notify.error({ title: 'Failed to sign in, please try again.' }); |
68 | | - } finally { |
69 | | - setIsConnecting(false); |
70 | | - track.$.$.auth.oauth({ provider }); |
71 | | - } |
72 | | - }, [authService, provider]); |
73 | 48 |
|
74 | 49 | return ( |
75 | | - <Button |
76 | | - key={provider} |
77 | | - variant="primary" |
78 | | - block |
79 | | - size="extraLarge" |
80 | | - style={{ marginTop: 30, width: '100%' }} |
81 | | - prefix={icon} |
82 | | - onClick={onClick} |
| 50 | + <a |
| 51 | + href={`/oauth/login?provider=${provider}`} |
| 52 | + target="_blank" |
| 53 | + rel="noreferrer" |
83 | 54 | > |
84 | | - Continue with {provider} |
85 | | - {isConnecting && '...'} |
86 | | - </Button> |
| 55 | + <Button |
| 56 | + key={provider} |
| 57 | + variant="primary" |
| 58 | + block |
| 59 | + size="extraLarge" |
| 60 | + style={{ marginTop: 30, width: '100%' }} |
| 61 | + prefix={icon} |
| 62 | + > |
| 63 | + Continue with {provider} |
| 64 | + </Button> |
| 65 | + </a> |
87 | 66 | ); |
88 | 67 | } |
0 commit comments