mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-01 17:50:50 +08:00
feat(mobile): improve notify for login failed
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { notify } from '@affine/component';
|
||||
import { getStoreManager } from '@affine/core/blocksuite/manager/store';
|
||||
import { AffineContext } from '@affine/core/components/context';
|
||||
import { AppFallback } from '@affine/core/mobile/components/app-fallback';
|
||||
@@ -295,6 +296,24 @@ window.addEventListener('focus', () => {
|
||||
});
|
||||
frameworkProvider.get(LifecycleService).applicationStart();
|
||||
|
||||
const getErrorMessage = (error: unknown, fallback: string) => {
|
||||
if (typeof error === 'string' && error) {
|
||||
return error;
|
||||
}
|
||||
if (error instanceof Error && error.message) {
|
||||
return error.message;
|
||||
}
|
||||
return fallback;
|
||||
};
|
||||
|
||||
const notifyAuthenticationError = (error: unknown, fallback: string) => {
|
||||
console.error(fallback, error);
|
||||
notify.error({
|
||||
title: I18n['com.affine.auth.toast.title.failed'](),
|
||||
message: getErrorMessage(error, fallback),
|
||||
});
|
||||
};
|
||||
|
||||
CapacitorApp.addListener('appUrlOpen', ({ url }) => {
|
||||
// try to close browser if it's open
|
||||
InAppBrowser.close().catch(e => console.error('Failed to close browser', e));
|
||||
@@ -311,7 +330,10 @@ CapacitorApp.addListener('appUrlOpen', ({ url }) => {
|
||||
(method !== 'magic-link' && method !== 'oauth') ||
|
||||
!payload
|
||||
) {
|
||||
console.error('Invalid authentication url', url);
|
||||
notifyAuthenticationError(
|
||||
new Error('Invalid authentication url'),
|
||||
'Invalid authentication url'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -323,7 +345,12 @@ CapacitorApp.addListener('appUrlOpen', ({ url }) => {
|
||||
const serversService = frameworkProvider.get(ServersService);
|
||||
const server = serversService.getServerByBaseUrl(serverBaseUrl);
|
||||
if (!server) {
|
||||
console.error('Authentication callback server not found', serverBaseUrl);
|
||||
notifyAuthenticationError(
|
||||
new Error(
|
||||
`Authentication callback server not found: ${serverBaseUrl}`
|
||||
),
|
||||
'Authentication callback server not found'
|
||||
);
|
||||
return;
|
||||
}
|
||||
authService = server.scope.get(AuthService);
|
||||
@@ -332,15 +359,19 @@ CapacitorApp.addListener('appUrlOpen', ({ url }) => {
|
||||
if (method === 'oauth') {
|
||||
authService
|
||||
.signInOauth(payload.code, payload.state, payload.provider)
|
||||
.catch(console.error);
|
||||
.catch(error =>
|
||||
notifyAuthenticationError(error, 'Failed to sign in with OAuth')
|
||||
);
|
||||
} else if (method === 'magic-link') {
|
||||
authService
|
||||
.signInMagicLink(payload.email, payload.token)
|
||||
.catch(console.error);
|
||||
.catch(error =>
|
||||
notifyAuthenticationError(error, 'Failed to sign in with magic link')
|
||||
);
|
||||
}
|
||||
}
|
||||
}).catch(e => {
|
||||
console.error(e);
|
||||
notifyAuthenticationError(e, 'Failed to handle authentication callback');
|
||||
});
|
||||
|
||||
const ThemeProvider = () => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { notify } from '@affine/component';
|
||||
import { getStoreManager } from '@affine/core/blocksuite/manager/store';
|
||||
import { AffineContext } from '@affine/core/components/context';
|
||||
import { AppFallback } from '@affine/core/mobile/components/app-fallback';
|
||||
@@ -408,6 +409,24 @@ window.addEventListener('focus', () => {
|
||||
});
|
||||
frameworkProvider.get(LifecycleService).applicationStart();
|
||||
|
||||
const getErrorMessage = (error: unknown, fallback: string) => {
|
||||
if (typeof error === 'string' && error) {
|
||||
return error;
|
||||
}
|
||||
if (error instanceof Error && error.message) {
|
||||
return error.message;
|
||||
}
|
||||
return fallback;
|
||||
};
|
||||
|
||||
const notifyAuthenticationError = (error: unknown, fallback: string) => {
|
||||
console.error(fallback, error);
|
||||
notify.error({
|
||||
title: I18n['com.affine.auth.toast.title.failed'](),
|
||||
message: getErrorMessage(error, fallback),
|
||||
});
|
||||
};
|
||||
|
||||
CapacitorApp.addListener('appUrlOpen', ({ url }) => {
|
||||
// try to close browser if it's open
|
||||
Browser.close().catch(e => console.error('Failed to close browser', e));
|
||||
@@ -424,7 +443,10 @@ CapacitorApp.addListener('appUrlOpen', ({ url }) => {
|
||||
(method !== 'magic-link' && method !== 'oauth') ||
|
||||
!payload
|
||||
) {
|
||||
console.error('Invalid authentication url', url);
|
||||
notifyAuthenticationError(
|
||||
new Error('Invalid authentication url'),
|
||||
'Invalid authentication url'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -435,23 +457,34 @@ CapacitorApp.addListener('appUrlOpen', ({ url }) => {
|
||||
if (serverBaseUrl) {
|
||||
const serversService = frameworkProvider.get(ServersService);
|
||||
const server = serversService.getServerByBaseUrl(serverBaseUrl);
|
||||
if (server) {
|
||||
authService = server.scope.get(AuthService);
|
||||
if (!server) {
|
||||
notifyAuthenticationError(
|
||||
new Error(
|
||||
`Authentication callback server not found: ${serverBaseUrl}`
|
||||
),
|
||||
'Authentication callback server not found'
|
||||
);
|
||||
return;
|
||||
}
|
||||
authService = server.scope.get(AuthService);
|
||||
}
|
||||
|
||||
if (method === 'oauth') {
|
||||
authService
|
||||
.signInOauth(payload.code, payload.state, payload.provider)
|
||||
.catch(console.error);
|
||||
.catch(error =>
|
||||
notifyAuthenticationError(error, 'Failed to sign in with OAuth')
|
||||
);
|
||||
} else if (method === 'magic-link') {
|
||||
authService
|
||||
.signInMagicLink(payload.email, payload.token)
|
||||
.catch(console.error);
|
||||
.catch(error =>
|
||||
notifyAuthenticationError(error, 'Failed to sign in with magic link')
|
||||
);
|
||||
}
|
||||
}
|
||||
}).catch(e => {
|
||||
console.error(e);
|
||||
notifyAuthenticationError(e, 'Failed to handle authentication callback');
|
||||
});
|
||||
|
||||
AppTrackingTransparency.requestPermission().catch(e => {
|
||||
|
||||
Reference in New Issue
Block a user