Skip to content

Commit

Permalink
fix(core): auth events are not continuous (#8874)
Browse files Browse the repository at this point in the history
  • Loading branch information
forehalo authored Nov 20, 2024
1 parent cc0462e commit 8b066a4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions packages/frontend/core/src/components/affine/auth/oauth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Skeleton } from '@affine/component';
import { Button } from '@affine/component/ui/button';
import { UrlService } from '@affine/core/modules/url';
import { OAuthProviderType } from '@affine/graphql';
import track from '@affine/track';
import { GithubIcon, GoogleDuotoneIcon } from '@blocksuite/icons/rc';
import { useLiveData, useService } from '@toeverything/infra';
import { type ReactElement, useCallback } from 'react';
Expand Down Expand Up @@ -86,6 +87,8 @@ function OAuthProvider({
const oauthUrl =
BUILD_CONFIG.serverUrlPrefix + `/oauth/login?${params.toString()}`;

track.$.$.auth.signIn({ method: 'oauth', provider });

popupWindow(oauthUrl);
}, [popupWindow, provider, redirectUrl, scheme]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ export function setupTracker() {
});

AIProvider.slots.requestLogin.on(() => {
track.$.$.auth.signIn({
control: 'aiAction',
});
track.doc.editor.aiActions.requestSignIn();
});

AIProvider.slots.actions.on(event => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const SignInItem = () => {
const t = useI18n();

const onClickSignIn = useCallback(() => {
track.$.navigationPanel.workspaceList.signIn();
track.$.navigationPanel.workspaceList.requestSignIn();
setOpen(state => ({
...state,
openModal: true,
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/core/src/modules/cloud/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ export class AuthService extends Service {
client: string,
/** @deprecated*/ redirectUrl?: string
) {
track.$.$.auth.signIn({ method: 'oauth', provider });
try {
const res = await this.fetchService.fetch('/api/oauth/preflight', {
method: 'POST',
Expand Down
12 changes: 9 additions & 3 deletions packages/frontend/track/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ type ShareEvents =
| 'copyShareLink'
| 'openShareMenu'
| 'share';
type AuthEvents = 'signIn' | 'signInFail' | 'signedIn' | 'signOut';
type AuthEvents =
| 'requestSignIn'
| 'signIn'
| 'signInFail'
| 'signedIn'
| 'signOut';
type AccountEvents = 'uploadAvatar' | 'removeAvatar' | 'updateUserName';
type PaymentEvents =
| 'viewPlans'
Expand Down Expand Up @@ -143,7 +148,7 @@ const PageEvents = {
$: {
$: {
$: ['createWorkspace', 'checkout'],
auth: ['signIn', 'signedIn', 'signInFail', 'signOut'],
auth: ['requestSignIn', 'signIn', 'signedIn', 'signInFail', 'signOut'],
},
sharePanel: {
$: ['createShareLink', 'copyShareLink', 'export', 'open'],
Expand Down Expand Up @@ -220,8 +225,8 @@ const PageEvents = {
others: ['navigate'],
importModal: ['open'],
workspaceList: [
'requestSignIn',
'open',
'signIn',
'createWorkspace',
'createDoc',
'openSettings',
Expand Down Expand Up @@ -278,6 +283,7 @@ const PageEvents = {
formatToolbar: ['bold'],
pageRef: ['navigate'],
toolbar: ['copyBlockToLink'],
aiActions: ['requestSignIn'],
},
inlineDocInfo: {
$: ['toggle'],
Expand Down

0 comments on commit 8b066a4

Please sign in to comment.