feat(mobile): ios oauth & magic-link login (#8581)

Co-authored-by: EYHN <cneyhn@gmail.com>
This commit is contained in:
Cats Juice
2024-10-28 14:12:33 +08:00
committed by GitHub
parent d6ec4cc597
commit 06dda70319
59 changed files with 929 additions and 219 deletions

View File

@@ -0,0 +1,20 @@
import type { Framework } from '@toeverything/infra';
import { ClientSchemaProvider } from './providers/client-schema';
import { PopupWindowProvider } from './providers/popup-window';
import { UrlService } from './services/url';
export { ClientSchemaProvider } from './providers/client-schema';
export { PopupWindowProvider } from './providers/popup-window';
export { UrlService } from './services/url';
export const configureUrlModule = (container: Framework) => {
container.service(
UrlService,
f =>
new UrlService(
f.getOptional(PopupWindowProvider),
f.getOptional(ClientSchemaProvider)
)
);
};

View File

@@ -0,0 +1,12 @@
import { createIdentifier } from '@toeverything/infra';
export interface ClientSchemaProvider {
/**
* Get the client schema in the current environment, used for the user to complete the authentication process in the browser and redirect back to the app.
*/
getClientSchema(): string | undefined;
}
export const ClientSchemaProvider = createIdentifier<ClientSchemaProvider>(
'ClientSchemaProvider'
);

View File

@@ -0,0 +1,13 @@
import { createIdentifier } from '@toeverything/infra';
export interface PopupWindowProvider {
/**
* open a popup window, provide different implementations in different environments.
* e.g. in electron, use system default browser to open a popup window.
*/
open(url: string): void;
}
export const PopupWindowProvider = createIdentifier<PopupWindowProvider>(
'PopupWindowProvider'
);

View File

@@ -0,0 +1,31 @@
import { Service } from '@toeverything/infra';
import type { ClientSchemaProvider } from '../providers/client-schema';
import type { PopupWindowProvider } from '../providers/popup-window';
export class UrlService extends Service {
constructor(
// those providers are optional, because they are not always available in some environments
private readonly popupWindowProvider?: PopupWindowProvider,
private readonly clientSchemaProvider?: ClientSchemaProvider
) {
super();
}
getClientSchema() {
return this.clientSchemaProvider?.getClientSchema();
}
/**
* open a popup window, provide different implementations in different environments.
* e.g. in electron, use system default browser to open a popup window.
*
* @param url only full url with http/https protocol is supported
*/
openPopupWindow(url: string) {
if (!url.startsWith('http')) {
throw new Error('only full url with http/https protocol is supported');
}
this.popupWindowProvider?.open(url);
}
}