solid-supabase
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

solid-supabase

solid-supabase

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

Installation

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

For supabase-js v1, install solid-supabase@0.2.x instead.

Quick start

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

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(
  () => (
    <SupabaseProvider client={supabase}>
      <App />
    </SupabaseProvider>
  ),
  document.getElementById('root'),
)

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

Use the primitive

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 (
    <Switch>
      <Match when={data.loading}>
        <div>Loading...</div>
      </Match>
      <Match when={data.error}>
        <div>{data.error}</div>
      </Match>
      <Match when={data()}>
        <pre>{JSON.stringify(data(), null, 2)}</pre>
        <button onClick={refetch}>Refetch</button>
      </Match>
    </Switch>
  )
}

export default App

Other available primitives

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.5.083latest

Version History

VersionDownloads (Last 7 Days)Published
0.5.083
0.4.00
0.3.20
0.3.10
0.3.00
0.2.90
0.2.80
0.2.70
0.2.60
0.2.50
0.2.40
0.2.30
0.2.20
0.2.10
0.2.00
0.1.00
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i solid-supabase

Weekly Downloads

83

Version

0.5.0

License

MIT

Unpacked Size

14.7 kB

Total Files

10

Last publish

Collaborators

  • wobsoriano