Skip to content

Commit

Permalink
chore: adjust code
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmFly committed Dec 20, 2024
1 parent 8583119 commit f019706
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hoo
import {
AuthService,
CaptchaService,
isBackendError,
ServerService,
} from '@affine/core/modules/cloud';
import { Unreachable } from '@affine/env/constant';
Expand Down Expand Up @@ -91,15 +90,11 @@ export const SignInWithPasswordStep = ({
});
} catch (err) {
console.error(err);
if (
err instanceof Error &&
isBackendError(err) &&
UserFriendlyError.fromAnyError(err).name ===
ErrorNames.UNSUPPORTED_CLIENT_VERSION
) {
const { action } = UserFriendlyError.fromAnyError(err).args;
const userFriendlyError = UserFriendlyError.fromAnyError(err);
if (userFriendlyError.name === ErrorNames.UNSUPPORTED_CLIENT_VERSION) {
const { action } = userFriendlyError.args;
nav(
`/sign-in?error=${encodeURIComponent(err.message)}&action=${encodeURIComponent(action as string)}`
`/sign-in?error=${encodeURIComponent(userFriendlyError.message)}&action=${encodeURIComponent(action as string)}`
);
return;
}
Expand Down
14 changes: 5 additions & 9 deletions packages/frontend/core/src/desktop/pages/auth/magic-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useNavigate,
} from 'react-router-dom';

import { AuthService, isBackendError } from '../../../modules/cloud';
import { AuthService } from '../../../modules/cloud';
import { supportedClient } from './common';

interface LoaderData {
Expand Down Expand Up @@ -80,15 +80,11 @@ export const Component = () => {
});
})
.catch(err => {
if (
err instanceof Error &&
isBackendError(err) &&
UserFriendlyError.fromAnyError(err).name ===
ErrorNames.UNSUPPORTED_CLIENT_VERSION
) {
const { action } = UserFriendlyError.fromAnyError(err).args;
const userFriendlyError = UserFriendlyError.fromAnyError(err);
if (userFriendlyError.name === ErrorNames.UNSUPPORTED_CLIENT_VERSION) {
const { action } = userFriendlyError.args;
nav(
`/sign-in?error=${encodeURIComponent(err.message)}&action=${encodeURIComponent(action as string)}`
`/sign-in?error=${encodeURIComponent(userFriendlyError.message)}&action=${encodeURIComponent(action as string)}`
);
return;
}
Expand Down
14 changes: 5 additions & 9 deletions packages/frontend/core/src/desktop/pages/auth/oauth-callback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useNavigate,
} from 'react-router-dom';

import { AuthService, isBackendError } from '../../../modules/cloud';
import { AuthService } from '../../../modules/cloud';
import { supportedClient } from './common';

interface LoaderData {
Expand Down Expand Up @@ -82,15 +82,11 @@ export const Component = () => {
nav(redirectUri ?? '/');
})
.catch(err => {
if (
err instanceof Error &&
isBackendError(err) &&
UserFriendlyError.fromAnyError(err).name ===
ErrorNames.UNSUPPORTED_CLIENT_VERSION
) {
const { action } = UserFriendlyError.fromAnyError(err).args;
const userFriendlyError = UserFriendlyError.fromAnyError(err);
if (userFriendlyError.name === ErrorNames.UNSUPPORTED_CLIENT_VERSION) {
const { action } = userFriendlyError.args;
nav(
`/sign-in?error=${encodeURIComponent(err.message)}&action=${encodeURIComponent(action as string)}`
`/sign-in?error=${encodeURIComponent(userFriendlyError.message)}&action=${encodeURIComponent(action as string)}`
);
return;
}
Expand Down

0 comments on commit f019706

Please sign in to comment.