Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wobsoriano/solid-supabase

A simple wrapper around Supabase.js to enable usage within Solid.
https://github.com/wobsoriano/solid-supabase

solid solid-js supabase

Last synced: 4 months ago
JSON representation

A simple wrapper around Supabase.js to enable usage within Solid.

Awesome Lists containing this project

README

        


solid-supabase

# solid-supabase

A simple wrapper around Supabase.js to enable usage within Solid.

## Installation

```bash
npm install @supabase/supabase-js solid-supabase # or pnpm or yarn
```

## Quick start

In the root of your app, use the `SupabaseProvider` and pass the supabase client with your credentials.

```tsx
import { render } from 'solid-js/web'
import { createClient } from '@supabase/supabase-js'
import { SupabaseProvider } from 'solid-supabase'
import App from './App'

const supabase = createClient('SUPABASE_URL', 'SUPABASE_KEY')

render(
() => (



),
document.getElementById('root'),
)
```

This will make the supabase client available anywhere along the component tree.

## Use the primitive

```tsx
import { Match, Switch, createResource, createSignal } from 'solid-js'
import { useSupabase } from 'solid-supabase'

const App = () => {
const supabase = useSupabase()

const [postId] = createSignal(1)
const [data, { refetch }] = createResource(postId, (arg) => {
return supabase.from('posts').select('*').eq('id', arg)
})

return (


Loading...



{data.error}



{JSON.stringify(data(), null, 2)}

Refetch


)
}

export default App
```

Other available primitives

```ts
import {
useOnAuthStateChange,
useSupabaseAuth,
useSupabaseFrom,
useSupabaseStorage,
} from 'solid-supabase'

const auth = useSupabaseAuth() // auth.signOut()
const storage = useSupabaseStorage() // storage.listBuckets()
const from = useSupabaseFrom() // from('posts').select('*').eq('id', arg)

useOnAuthStateChange((event, session) => {
console.log(event, session)
})
```

## License

MIT