mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
feat: support google login on desktop (#4053)
Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
@@ -35,7 +35,7 @@ export const AfterSignInSendEmail: FC<AuthPanelProps> = ({
|
||||
onClick={useCallback(() => {
|
||||
signInCloud('email', {
|
||||
email,
|
||||
callbackUrl: buildCallbackUrl('signIn'),
|
||||
callbackUrl: buildCallbackUrl('/auth/signIn'),
|
||||
redirect: true,
|
||||
}).catch(console.error);
|
||||
}, [email])}
|
||||
|
||||
@@ -34,7 +34,7 @@ export const AfterSignUpSendEmail: FC<AuthPanelProps> = ({
|
||||
onClick={useCallback(() => {
|
||||
signInCloud('email', {
|
||||
email: email,
|
||||
callbackUrl: buildCallbackUrl('signUp'),
|
||||
callbackUrl: buildCallbackUrl('/auth/signUp'),
|
||||
redirect: true,
|
||||
}).catch(console.error);
|
||||
}, [email])}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { isDesktop } from '@affine/env/constant';
|
||||
|
||||
type Action = 'signUp' | 'changePassword' | 'signIn' | 'signUp';
|
||||
|
||||
export function buildCallbackUrl(action: Action) {
|
||||
const callbackUrl = `/auth/${action}`;
|
||||
export function buildCallbackUrl(callbackUrl: string) {
|
||||
const params: string[][] = [];
|
||||
if (isDesktop && window.appInfo.schema) {
|
||||
params.push(['schema', window.appInfo.schema]);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { AuthInput, ModalHeader } from '@affine/component/auth-components';
|
||||
import { pushNotificationAtom } from '@affine/component/notification-center';
|
||||
import type { Notification } from '@affine/component/notification-center/index.jotai';
|
||||
import { isDesktop } from '@affine/env/constant';
|
||||
import { getUserQuery } from '@affine/graphql';
|
||||
import { Trans } from '@affine/i18n';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
@@ -69,7 +70,7 @@ export const SignIn: FC<AuthPanelProps> = ({
|
||||
if (user) {
|
||||
signInCloud('email', {
|
||||
email: email,
|
||||
callbackUrl: buildCallbackUrl('signIn'),
|
||||
callbackUrl: buildCallbackUrl('/auth/signIn'),
|
||||
redirect: false,
|
||||
})
|
||||
.then(res => handleSendEmailError(res, pushNotification))
|
||||
@@ -78,7 +79,7 @@ export const SignIn: FC<AuthPanelProps> = ({
|
||||
} else {
|
||||
signInCloud('email', {
|
||||
email: email,
|
||||
callbackUrl: buildCallbackUrl('signUp'),
|
||||
callbackUrl: buildCallbackUrl('/auth/signUp'),
|
||||
redirect: false,
|
||||
})
|
||||
.then(res => handleSendEmailError(res, pushNotification))
|
||||
@@ -103,7 +104,16 @@ export const SignIn: FC<AuthPanelProps> = ({
|
||||
}}
|
||||
icon={<GoogleDuotoneIcon />}
|
||||
onClick={useCallback(() => {
|
||||
signInCloud('google').catch(console.error);
|
||||
if (isDesktop) {
|
||||
open(
|
||||
`/desktop-signin?provider=google&callback_url=${buildCallbackUrl(
|
||||
'/open-app/oauth-jwt'
|
||||
)}`,
|
||||
'_target'
|
||||
);
|
||||
} else {
|
||||
signInCloud('google').catch(console.error);
|
||||
}
|
||||
}, [])}
|
||||
>
|
||||
{t['Continue with Google']()}
|
||||
|
||||
Reference in New Issue
Block a user