feat(android): sign-in with google & magic-link & email (#9868)

- [chore(android): migrate to version catalog](https://github.com/toeverything/AFFiNE/pull/9868/commits/16c0fb66e758abe9371f93d369e33db49f27807a)
- [feat(android): integrate apollo](https://github.com/toeverything/AFFiNE/pull/9868/commits/4dcf93b4f94b8a0c8cf6ba9ede21b8b7e0499004)
- [fix(android): fix android email sign-in](https://github.com/toeverything/AFFiNE/pull/9868/commits/752cf34f33db47721d013d2fab868029781b1132)
- [chore(android): add stable/canary environment](https://github.com/toeverything/AFFiNE/pull/9868/commits/72a96bfa5f741c690759f1fd09efa3cd812ab232)
- [feat(android): set cookies for apollo client](https://github.com/toeverything/AFFiNE/pull/9868/commits/7664cc4f1939b9dd42a2a616dc676ca9500c27d4)
- [feat(android): google & magic-link sign-in](https://github.com/toeverything/AFFiNE/pull/9868/commits/c54ce3b43b4d2f7d927a7784796ee3d20cd55dc9)
- [eat(android): change logo](https://github.com/toeverything/AFFiNE/pull/9868/commits/8c5062adbc44545851c998572f01a16caf6ce83b)
- [chore(android): fix pipleline](https://github.com/toeverything/AFFiNE/pull/9868/commits/4a68299be4b04935b101e32b0da74cc07f43b785)
- [fix(android): rebase issues](https://github.com/toeverything/AFFiNE/pull/9868/commits/c6858c5ecfa9288b2bad4b4bd6c800f5d8aef47e)
- [docs(android): update README for compat with java 21](https://github.com/toeverything/AFFiNE/pull/9868/commits/6eac3ba0dca3af8e1bace20a260390b57b7d590b)
- [fix(android): android pipeline](https://github.com/toeverything/AFFiNE/pull/9868/commits/1103c87880a5a01a8fd55e01c80a43934b8b61ef)
This commit is contained in:
aki-chang-dev
2025-02-05 06:08:27 +00:00
parent cbb73d8034
commit 2607e34063
65 changed files with 2378 additions and 279 deletions
@@ -3,15 +3,20 @@ import { AppFallback } from '@affine/core/mobile/components/app-fallback';
import { configureMobileModules } from '@affine/core/mobile/modules';
import { router } from '@affine/core/mobile/router';
import { configureCommonModules } from '@affine/core/modules';
import { AuthService, DefaultServerService } from '@affine/core/modules/cloud';
import { I18nProvider } from '@affine/core/modules/i18n';
import { LifecycleService } from '@affine/core/modules/lifecycle';
import {
configureLocalStorageStateStorageImpls,
NbstoreProvider,
} from '@affine/core/modules/storage';
import { PopupWindowProvider } from '@affine/core/modules/url';
import { ClientSchemeProvider } from '@affine/core/modules/url/providers/client-schema';
import { configureBrowserWorkbenchModule } from '@affine/core/modules/workbench';
import { configureBrowserWorkspaceFlavours } from '@affine/core/modules/workspace-engine';
import { WorkerClient } from '@affine/nbstore/worker/client';
import { App as CapacitorApp } from '@capacitor/app';
import { InAppBrowser } from '@capgo/inappbrowser';
import { Framework, FrameworkRoot, getCurrentStore } from '@toeverything/infra';
import { OpClient } from '@toeverything/infra/op';
import { Suspense } from 'react';
@@ -43,12 +48,62 @@ framework.impl(NbstoreProvider, {
});
const frameworkProvider = framework.provider();
framework.impl(PopupWindowProvider, {
open: (url: string) => {
InAppBrowser.open({
url: url,
}).catch(console.error);
},
});
framework.impl(ClientSchemeProvider, {
getClientScheme() {
return 'affine';
},
});
// setup application lifecycle events, and emit application start event
window.addEventListener('focus', () => {
frameworkProvider.get(LifecycleService).applicationFocus();
});
frameworkProvider.get(LifecycleService).applicationStart();
CapacitorApp.addListener('appUrlOpen', ({ url }) => {
// try to close browser if it's open
InAppBrowser.close().catch(e => console.error('Failed to close browser', e));
const urlObj = new URL(url);
if (urlObj.hostname === 'authentication') {
const method = urlObj.searchParams.get('method');
const payload = JSON.parse(urlObj.searchParams.get('payload') ?? 'false');
if (
!method ||
(method !== 'magic-link' && method !== 'oauth') ||
!payload
) {
console.error('Invalid authentication url', url);
return;
}
const authService = frameworkProvider
.get(DefaultServerService)
.server.scope.get(AuthService);
if (method === 'oauth') {
authService
.signInOauth(payload.code, payload.state, payload.provider)
.catch(console.error);
} else if (method === 'magic-link') {
authService
.signInMagicLink(payload.email, payload.token)
.catch(console.error);
}
}
}).catch(e => {
console.error(e);
});
export function App() {
return (
<Suspense>