-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupabase.ts
39 lines (33 loc) · 900 Bytes
/
supabase.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import 'react-native-url-polyfill/auto';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {createClient} from '@supabase/supabase-js';
import {decode} from 'base64-arraybuffer';
import type {Database} from './src/types/supabase';
import {supabaseAnonKey, supabaseUrl} from './config';
export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey, {
auth: {
storage: AsyncStorage,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
},
});
export const uploadFileToSupabase = async ({
base64: file,
bucket,
destPath,
}: {
base64: string;
bucket: string;
destPath: string;
}): Promise<string> => {
const {data, error} = await supabase.storage
.from(bucket)
.upload(destPath, decode(file), {
contentType: 'audio/m4a',
});
if (error) {
throw error;
}
return data.path;
};