Skip to content

Commit d69217b

Browse files
committed
add supabase utils
1 parent a76123e commit d69217b

File tree

4 files changed

+168
-113
lines changed

4 files changed

+168
-113
lines changed

apps/desktop2/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"@hypr/ui": "workspace:^",
2121
"@hypr/utils": "workspace:^",
2222
"@sentry/react": "^8.55.0",
23+
"@supabase/supabase-js": "^2.58.0",
24+
"@t3-oss/env-core": "^0.13.8",
2325
"@tanstack/react-router": "^1.132.41",
2426
"@tanstack/react-virtual": "^3.13.12",
2527
"@tauri-apps/api": "^2.8.0",

apps/desktop2/src/env.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createEnv } from "@t3-oss/env-core";
2+
import { z } from "zod";
3+
4+
export const env = createEnv({
5+
clientPrefix: "VITE_",
6+
client: {
7+
VITE_SUPABASE_URL: z.string().min(1),
8+
VITE_SUPABASE_ANON_KEY: z.string().min(1),
9+
},
10+
runtimeEnv: import.meta.env,
11+
emptyStringAsUndefined: true,
12+
});

apps/desktop2/src/supabase.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { createClient, processLock, type SupportedStorage } from "@supabase/supabase-js";
2+
import { getCurrentWindow } from "@tauri-apps/api/window";
3+
4+
import { env } from "./env";
5+
6+
const storage = null as unknown as SupportedStorage;
7+
8+
export const supabase = createClient(env.VITE_SUPABASE_URL, env.VITE_SUPABASE_ANON_KEY, {
9+
auth: {
10+
storage,
11+
autoRefreshToken: true,
12+
persistSession: true,
13+
detectSessionInUrl: false,
14+
lock: processLock,
15+
},
16+
});
17+
18+
const appWindow = getCurrentWindow();
19+
20+
appWindow.listen("tauri://focus", () => {
21+
supabase.auth.startAutoRefresh();
22+
});
23+
24+
appWindow.listen("tauri://blur", () => {
25+
supabase.auth.stopAutoRefresh();
26+
});

0 commit comments

Comments
 (0)