feat(mobile): ios oauth & magic-link login (#8581)
Co-authored-by: EYHN <cneyhn@gmail.com>
This commit is contained in:
20
packages/frontend/core/src/modules/url/index.ts
Normal file
20
packages/frontend/core/src/modules/url/index.ts
Normal 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)
|
||||
)
|
||||
);
|
||||
};
|
||||
@@ -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'
|
||||
);
|
||||
@@ -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'
|
||||
);
|
||||
31
packages/frontend/core/src/modules/url/services/url.ts
Normal file
31
packages/frontend/core/src/modules/url/services/url.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user