Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(desktop): stub better-auth client for Electron renderer (#12563)

Innei37e90cebfa2b
diff --git a/apps/desktop/resources/error.html b/apps/desktop/resources/error.html
index 781aebb4f8e..663f9cbc672 100644
--- a/apps/desktop/resources/error.html
+++ b/apps/desktop/resources/error.html
@@ -5,10 +5,18 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LobeHub - 连接错误</title>
<style>
- body {
+ .drag-bar {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ height: 32px;
-webkit-app-region: drag;
+ }
+
+ body {
margin: 0;
- padding: 0;
+ padding: 32px 0 0;
height: 100vh;
display: flex;
justify-content: center;
@@ -72,7 +80,6 @@
}
.retry-button {
- -webkit-app-region: no-drag;
padding: 0.75rem 1.5rem;
background-color: #f5f5f5;
color: #1f1f1f;
@@ -89,6 +96,7 @@
</style>
</head>
<body>
+ <div class="drag-bar"></div>
<div class="container">
<div class="error-icon">⚠️</div>
<h1 class="error-title">Connection Error</h1>
diff --git a/apps/desktop/resources/splash.html b/apps/desktop/resources/splash.html
index cb29472c325..5fd4cb90322 100644
--- a/apps/desktop/resources/splash.html
+++ b/apps/desktop/resources/splash.html
@@ -5,10 +5,18 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LobeHub</title>
<style>
- body {
+ .drag-bar {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ height: 48px;
-webkit-app-region: drag;
+ }
+
+ body {
margin: 0;
- padding: 0;
+ padding: 48px 0 0;
height: 100vh;
display: flex;
justify-content: center;
@@ -70,6 +78,7 @@
</style>
</head>
<body>
+ <div class="drag-bar"></div>
<div class="container">
<svg
class="lobe-brand-loading"
diff --git a/package.json b/package.json
index cbc1576cb7b..27e81ad5d0c 100644
--- a/package.json
+++ b/package.json
@@ -57,6 +57,7 @@
"desktop:package:local:reuse": "npm run package:local:reuse --prefix=./apps/desktop",
"dev": "tsx scripts/devStartupSequence.mts",
"dev:bun": "bun --bun next dev -p 3010",
+ "dev:desktop": "cd apps/desktop && pnpm run dev",
"dev:docker": "docker compose -f docker-compose/dev/docker-compose.yml up -d --wait postgresql redis rustfs searxng",
"dev:docker:down": "docker compose -f docker-compose/dev/docker-compose.yml down",
"dev:docker:reset": "docker compose -f docker-compose/dev/docker-compose.yml down -v && rm -rf docker-compose/dev/data && npm run dev:docker && pnpm db:migrate",
diff --git a/src/libs/better-auth/auth-client.desktop.ts b/src/libs/better-auth/auth-client.desktop.ts
new file mode 100644
index 00000000000..dc2615a4ede
--- /dev/null
+++ b/src/libs/better-auth/auth-client.desktop.ts
@@ -0,0 +1,58 @@
+import {
+ adminClient,
+ genericOAuthClient,
+ inferAdditionalFields,
+ magicLinkClient,
+} from 'better-auth/client/plugins';
+import { createAuthClient } from 'better-auth/react';
+
+import { type auth } from '@/auth';
+import { electronSyncSelectors } from '@/store/electron/selectors/sync';
+import { getElectronStoreState } from '@/store/electron/store';
+
+let _client: any = null;
+
+function getClient() {
+ if (!_client) {
+ const baseURL = electronSyncSelectors.remoteServerUrl(getElectronStoreState());
+
+ _client = createAuthClient({
+ baseURL,
+ plugins: [
+ adminClient(),
+ inferAdditionalFields<typeof auth>(),
+ genericOAuthClient(),
+ magicLinkClient(),
+ ],
+ });
+ }
+ return _client;
+}
+
+function lazyProp(key: string): any {
+ // Target must be a function for the Proxy apply trap to work
+ return new Proxy(function () {}, {
+ apply(_t, thisArg, args) {
+ return Reflect.apply(getClient()[key], thisArg, args);
+ },
+ get(_t, prop, receiver) {
+ const target = getClient()[key];
+ const value = Reflect.get(target, prop, receiver);
+ return typeof value === 'function' ? value.bind(target) : value;
+ },
+ });
+}
+
+export const changeEmail = lazyProp('changeEmail');
+export const linkSocial = lazyProp('linkSocial');
+export const oauth2 = lazyProp('oauth2');
+export const accountInfo = lazyProp('accountInfo');
+export const listAccounts = lazyProp('listAccounts');
+export const requestPasswordReset = lazyProp('requestPasswordReset');
+export const resetPassword = lazyProp('resetPassword');
+export const sendVerificationEmail = lazyProp('sendVerificationEmail');
+export const signIn = lazyProp('signIn');
+export const signOut = lazyProp('signOut');
+export const signUp = lazyProp('signUp');
+export const unlinkAccount = lazyProp('unlinkAccount');
+export const useSession = lazyProp('useSession');
diff --git a/src/routes/(main)/settings/profile/index.tsx b/src/routes/(main)/settings/profile/index.tsx
index 57b1da744b6..74a05c84421 100644
--- a/src/routes/(main)/settings/profile/index.tsx
+++ b/src/routes/(main)/settings/profile/index.tsx
@@ -131,7 +131,7 @@ const ProfileSetting = ({ mobile }: ProfileSettingProps) => {
)}
{/* SSO Providers Row */}
- {isLogin && (
+ {isLogin && !isDesktop && (
<>
<Divider style={{ margin: 0 }} />
<ProfileRow label={t('profile.sso.providers')} mobile={mobile}>