mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
feat(mobile): ios oauth & magic-link login (#8581)
Co-authored-by: EYHN <cneyhn@gmail.com>
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
export * from './create-emotion-cache';
|
||||
export * from './event';
|
||||
export * from './extract-emoji-icon';
|
||||
export * from './popup';
|
||||
export * from './string2color';
|
||||
export * from './toast';
|
||||
export * from './unflatten-object';
|
||||
export * from './url';
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { apis } from '@affine/electron-api';
|
||||
|
||||
const logger = new DebugLogger('popup');
|
||||
|
||||
const origin =
|
||||
BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS || BUILD_CONFIG.isAndroid
|
||||
? BUILD_CONFIG.serverUrlPrefix
|
||||
: location.origin;
|
||||
|
||||
/**
|
||||
* @deprecated need to be refactored as [UrlService] dependencies on [ServerConfigService]
|
||||
*/
|
||||
export function popupWindow(target: string) {
|
||||
const isFullUrl = /^https?:\/\//.test(target);
|
||||
|
||||
const redirectProxy = origin + '/redirect-proxy';
|
||||
target = isFullUrl ? target : origin + target;
|
||||
|
||||
const targetUrl = new URL(target);
|
||||
|
||||
let url: string;
|
||||
// safe to open directly if in the same origin
|
||||
if (targetUrl.origin === origin) {
|
||||
url = target;
|
||||
} else {
|
||||
const search = new URLSearchParams({
|
||||
redirect_uri: target,
|
||||
});
|
||||
|
||||
url = `${redirectProxy}?${search.toString()}`;
|
||||
}
|
||||
|
||||
if (BUILD_CONFIG.isElectron) {
|
||||
apis?.ui.openExternal(url).catch(e => {
|
||||
logger.error('Failed to open external URL', e);
|
||||
});
|
||||
} else {
|
||||
window.open(url, '_blank', `noreferrer noopener`);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import { appInfo } from '@affine/electron-api';
|
||||
|
||||
interface AppUrlOptions {
|
||||
desktop?: boolean | string;
|
||||
openInHiddenWindow?: boolean;
|
||||
redirectFromWeb?: boolean;
|
||||
}
|
||||
|
||||
export function buildAppUrl(path: string, opts: AppUrlOptions = {}) {
|
||||
// TODO(@EYHN): should use server base url
|
||||
const webBase = BUILD_CONFIG.serverUrlPrefix;
|
||||
// TODO(@pengx17): how could we know the corresponding app schema in web environment
|
||||
if (opts.desktop && appInfo?.schema) {
|
||||
const urlCtor = new URL(path, webBase);
|
||||
|
||||
if (opts.openInHiddenWindow) {
|
||||
urlCtor.searchParams.set('hidden', 'true');
|
||||
}
|
||||
|
||||
const url = `${appInfo.schema}://${urlCtor.pathname}${urlCtor.search}`;
|
||||
|
||||
if (opts.redirectFromWeb) {
|
||||
const redirect_uri = new URL('/open-app/url', webBase);
|
||||
redirect_uri.searchParams.set('url', url);
|
||||
|
||||
return redirect_uri.toString();
|
||||
}
|
||||
|
||||
return url;
|
||||
} else {
|
||||
return new URL(path, webBase).toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user