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

@@ -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';

View File

@@ -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`);
}
}

View File

@@ -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();
}
}