refactor(core): auth (#7999)

closes AF-753 AF-1227
This commit is contained in:
forehalo
2024-09-03 09:03:43 +00:00
parent 8b0afd6eeb
commit e33aa35f7e
18 changed files with 286 additions and 166 deletions

View File

@@ -6,3 +6,4 @@ export * from './popup';
export * from './string2color';
export * from './toast';
export * from './unflatten-object';
export * from './url';

View File

@@ -0,0 +1,33 @@
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 = runtimeConfig.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();
}
}