mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 12:36:24 +08:00
feat(core): add subscribe link (#6610)
This commit is contained in:
@@ -25,7 +25,7 @@ const OAuthProviderMap: Record<
|
||||
},
|
||||
};
|
||||
|
||||
export function OAuth() {
|
||||
export function OAuth({ redirectUri }: { redirectUri?: string | null }) {
|
||||
const serverConfig = useService(ServerConfigService).serverConfig;
|
||||
const oauth = useLiveData(serverConfig.features$.map(r => r?.oauth));
|
||||
const oauthProviders = useLiveData(
|
||||
@@ -42,11 +42,21 @@ export function OAuth() {
|
||||
}
|
||||
|
||||
return oauthProviders?.map(provider => (
|
||||
<OAuthProvider key={provider} provider={provider} />
|
||||
<OAuthProvider
|
||||
key={provider}
|
||||
provider={provider}
|
||||
redirectUri={redirectUri}
|
||||
/>
|
||||
));
|
||||
}
|
||||
|
||||
function OAuthProvider({ provider }: { provider: OAuthProviderType }) {
|
||||
function OAuthProvider({
|
||||
provider,
|
||||
redirectUri,
|
||||
}: {
|
||||
provider: OAuthProviderType;
|
||||
redirectUri?: string | null;
|
||||
}) {
|
||||
const { icon } = OAuthProviderMap[provider];
|
||||
const authService = useService(AuthService);
|
||||
const [isConnecting, setIsConnecting] = useState(false);
|
||||
@@ -54,7 +64,7 @@ function OAuthProvider({ provider }: { provider: OAuthProviderType }) {
|
||||
const onClick = useAsyncCallback(async () => {
|
||||
try {
|
||||
setIsConnecting(true);
|
||||
await authService.signInOauth(provider);
|
||||
await authService.signInOauth(provider, redirectUri);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notify.error({ message: 'Failed to sign in, please try again.' });
|
||||
@@ -62,7 +72,7 @@ function OAuthProvider({ provider }: { provider: OAuthProviderType }) {
|
||||
setIsConnecting(false);
|
||||
mixpanel.track('OAuth', { provider });
|
||||
}
|
||||
}, [authService, provider]);
|
||||
}, [authService, provider, redirectUri]);
|
||||
|
||||
return (
|
||||
<Button
|
||||
|
||||
@@ -8,6 +8,7 @@ import { ArrowDownBigIcon } from '@blocksuite/icons';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
import type { FC } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
|
||||
import { AuthService } from '../../../modules/cloud';
|
||||
import { mixpanel } from '../../../utils';
|
||||
@@ -29,7 +30,7 @@ export const SignIn: FC<AuthPanelProps> = ({
|
||||
}) => {
|
||||
const t = useAFFiNEI18N();
|
||||
const authService = useService(AuthService);
|
||||
|
||||
const [searchParams] = useSearchParams();
|
||||
const [isMutating, setIsMutating] = useState(false);
|
||||
const [verifyToken, challenge] = useCaptcha();
|
||||
|
||||
@@ -74,11 +75,21 @@ export const SignIn: FC<AuthPanelProps> = ({
|
||||
mixpanel.track_forms('SignIn', 'Email', {
|
||||
email,
|
||||
});
|
||||
await authService.sendEmailMagicLink(email, verifyToken, challenge);
|
||||
await authService.sendEmailMagicLink(
|
||||
email,
|
||||
verifyToken,
|
||||
challenge,
|
||||
searchParams.get('redirect_uri')
|
||||
);
|
||||
setAuthState('afterSignInSendEmail');
|
||||
}
|
||||
} else {
|
||||
await authService.sendEmailMagicLink(email, verifyToken, challenge);
|
||||
await authService.sendEmailMagicLink(
|
||||
email,
|
||||
verifyToken,
|
||||
challenge,
|
||||
searchParams.get('redirect_uri')
|
||||
);
|
||||
mixpanel.track_forms('SignUp', 'Email', {
|
||||
email,
|
||||
});
|
||||
@@ -95,7 +106,15 @@ export const SignIn: FC<AuthPanelProps> = ({
|
||||
}
|
||||
|
||||
setIsMutating(false);
|
||||
}, [authService, challenge, email, setAuthEmail, setAuthState, verifyToken]);
|
||||
}, [
|
||||
authService,
|
||||
challenge,
|
||||
email,
|
||||
searchParams,
|
||||
setAuthEmail,
|
||||
setAuthState,
|
||||
verifyToken,
|
||||
]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -104,7 +123,7 @@ export const SignIn: FC<AuthPanelProps> = ({
|
||||
subTitle={t['com.affine.brand.affineCloud']()}
|
||||
/>
|
||||
|
||||
<OAuth />
|
||||
<OAuth redirectUri={searchParams.get('redirect_uri')} />
|
||||
|
||||
<div className={style.authModalContent}>
|
||||
<AuthInput
|
||||
|
||||
Reference in New Issue
Block a user