Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folasade/imp 5 supabase client #6

Merged
merged 9 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/DummyQueries.tsx
stephaniewong2 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Button } from 'react-native-elements';
import { supabase } from './supabase';

export default function DummyQueries() {
async function allCases() {
const { data, error } = await supabase.from('Cases').select();
}
async function approvedCases() {
const { data, error } = await supabase
.from('Cases')
.select()
.filter('approved', 'is', 'True');
}
async function unapprovedCases() {
const { data, error } = await supabase
.from('Cases')
.select()
.filter('approved', 'is', 'False');
}
async function addCase() {
const dummyCase = {
approved: false,
title: 'Dummy Case',
summary: 'Testing intializing db',
image: 'no.jpg',
case_status: 'In Progress',
claim_link: 'berkeley.edu',
case_site: 'berkeley.edu',
opt_out_link: 'berkeley.edu',
};
const { error } = await supabase.from('Cases').insert(dummyCase);
}

return <Button title="Get Case Data" onPress={() => allCases()} />;
}
20 changes: 20 additions & 0 deletions lib/supabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import { createClient } from '@supabase/supabase-js';
import { useState } from 'react';
import 'react-native-url-polyfill/auto';
stephaniewong2 marked this conversation as resolved.
Show resolved Hide resolved

const [supabaseUrl, setSupabaseUrl] = useState<string>('');
const [supabaseAnonKey, setSupabaseAnonKey] = useState<string>('');

if (process.env.SUPABASE_URL && process.env.SUPABASE_ANON_KEY) {
setSupabaseUrl(process.env.SUPABASE_URL);
setSupabaseAnonKey(process.env.SUPABASE_ANON_KEY);
}
export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
auth: {
storage: AsyncStorage,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
},
});
Loading
Loading