forked from wangziqi/gongxue-base
feat: add taro h5 runtime deployment config
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import Taro from '@tarojs/taro';
|
||||
import { appEnv } from '@/env';
|
||||
import { appEnv, ensureRuntimeConfigLoaded } from '@/env';
|
||||
import type { ApiErrorPayload, ApiSession, TenantContext } from '@/types';
|
||||
import { getStorage, removeStorage, setStorage } from './storage';
|
||||
|
||||
@@ -67,6 +67,7 @@ export async function apiRequest<T>(
|
||||
headers?: Record<string, string>;
|
||||
} = {},
|
||||
): Promise<T> {
|
||||
await ensureRuntimeConfigLoaded();
|
||||
const tenant = getTenantContext();
|
||||
const session = getSession();
|
||||
const token = options.token ?? session?.token ?? null;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { createClient, type SupabaseClient } from '@supabase/supabase-js';
|
||||
import { appEnv } from '@/env';
|
||||
import { appEnv, ensureRuntimeConfigLoaded } from '@/env';
|
||||
|
||||
let client: SupabaseClient | null = null;
|
||||
let clientKey = '';
|
||||
|
||||
export function getSupabaseClient() {
|
||||
if (!appEnv.supabaseUrl || !appEnv.supabasePublishableKey) return null;
|
||||
if (!client) {
|
||||
const nextClientKey = `${appEnv.supabaseUrl}|${appEnv.supabasePublishableKey}`;
|
||||
if (!client || clientKey !== nextClientKey) {
|
||||
client = createClient(appEnv.supabaseUrl, appEnv.supabasePublishableKey, {
|
||||
auth: {
|
||||
persistSession: true,
|
||||
@@ -13,12 +15,18 @@ export function getSupabaseClient() {
|
||||
detectSessionInUrl: true,
|
||||
},
|
||||
});
|
||||
clientKey = nextClientKey;
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
export async function ensureSupabaseClient() {
|
||||
await ensureRuntimeConfigLoaded();
|
||||
return getSupabaseClient();
|
||||
}
|
||||
|
||||
export async function getSupabaseAccessToken() {
|
||||
const supabase = getSupabaseClient();
|
||||
const supabase = await ensureSupabaseClient();
|
||||
if (!supabase) return null;
|
||||
const { data } = await supabase.auth.getSession();
|
||||
return data.session?.access_token || null;
|
||||
|
||||
Reference in New Issue
Block a user