mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 18:16:15 +08:00
@@ -1,11 +1,15 @@
|
||||
import { Button } from '@affine/component/ui/button';
|
||||
import { ServerService } from '@affine/core/modules/cloud';
|
||||
import { notify } from '@affine/component/ui/notification';
|
||||
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
||||
import { AuthService, ServerService } from '@affine/core/modules/cloud';
|
||||
import { UrlService } from '@affine/core/modules/url';
|
||||
import { type UserFriendlyError } from '@affine/error';
|
||||
import { OAuthProviderType } from '@affine/graphql';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import track from '@affine/track';
|
||||
import { GithubIcon, GoogleIcon, LockIcon } from '@blocksuite/icons/rc';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
import { type ReactElement, type SVGAttributes, useCallback } from 'react';
|
||||
import { type ReactElement, type SVGAttributes } from 'react';
|
||||
|
||||
const OAuthProviderMap: Record<
|
||||
OAuthProviderType,
|
||||
@@ -64,9 +68,27 @@ function OAuthProvider({
|
||||
popupWindow: (url: string) => void;
|
||||
}) {
|
||||
const serverService = useService(ServerService);
|
||||
const auth = useService(AuthService);
|
||||
const { icon } = OAuthProviderMap[provider];
|
||||
const t = useI18n();
|
||||
|
||||
const onClick = useAsyncCallback(async () => {
|
||||
if (scheme && BUILD_CONFIG.isNative) {
|
||||
let oauthUrl = '';
|
||||
try {
|
||||
oauthUrl = await auth.oauthPreflight(provider, scheme);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
const err = e as UserFriendlyError;
|
||||
notify.error({
|
||||
title: t[`error.${err.name}`](err.data),
|
||||
});
|
||||
return;
|
||||
}
|
||||
popupWindow(oauthUrl);
|
||||
return;
|
||||
}
|
||||
|
||||
const onClick = useCallback(() => {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
params.set('provider', provider);
|
||||
@@ -88,7 +110,7 @@ function OAuthProvider({
|
||||
track.$.$.auth.signIn({ method: 'oauth', provider });
|
||||
|
||||
popupWindow(oauthUrl);
|
||||
}, [popupWindow, provider, redirectUrl, scheme, serverService]);
|
||||
}, [popupWindow, provider, redirectUrl, scheme, serverService, auth, t]);
|
||||
|
||||
return (
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user