Giter VIP home page Giter VIP logo

solid-supabase's Introduction

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

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

solid-supabase's People

Contributors

leweyse avatar thislight avatar wobsoriano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

solid-supabase's Issues

createSupabase must be used within a SupabaseContext.Provider

Hey there,

what I am trying to do is:
I want to show the updated profile in every component as soon as it is changed in the Account component.

I rebuild the problem here: https://codesandbox.io/s/crimson-dawn-djuqtc
(in index.tsx you need to add your url and key for supabase)

Here is how I tried to do it:
I added the SupabaseProvider in my index.tsx:
https://codesandbox.io/s/crimson-dawn-djuqtc?file=/src/components/Secure/Secure.tsx:142-159

Then I created a profileStore, to access and update the profile data from every component:
https://codesandbox.io/s/crimson-dawn-djuqtc?file=/src/store/profileStore.tsx

To update the user profile I created a Account component:
https://codesandbox.io/s/crimson-dawn-djuqtc?file=/src/components/Account/Account.tsx

The initial call works fine and the profile information is displayed.

As soon as I submit the form in Account.tsx this arrow is thrown:

index.js:1 Uncaught (in promise) Error: createSupabase must be used within a SupabaseContext.Provider

The error occurs in the profileStore in line 68:
https://codesandbox.io/s/crimson-dawn-djuqtc?file=/src/store/profileStore.tsx:1522-1558

It doesn't matter if I change this to "const supabase = createSupabase()".

What am I doing wrong? I am new to solidjs and I am sure I am missing something.
Is it a but (probably not) or am I implenting it wrong or is there a better / easier / suggested way to make this?

Thanks!

Whats the path to updating all of the outdated dependencies

Thank you for the starter template.

Given we are starting from scratch we'd at least like to try and make sure everything is up to date as possible. Is there an upgrade path? Or are these versions of dependencies needing to stay this way for compatibility?

createOnAuthStateChange - session is not a function error

I keep getting an error when using the primitive createOnAuthStateChange

auth.session is not a function

inside the primitives there is https://github.com/wobsoriano/solid-supabase/blob/master/src/primitives.ts

createRenderEffect(() => {
    if (client.auth.session())
      callback('SIGNED_IN', client.auth.session())

    onCleanup(() => {
      authListener?.unsubscribe()
    })
  })
}

if(client.auth.session()) <-- should this line use client.auth.session instead? and below line callback use client.auth.getSession()?

package.json specify wrong files for bundlers.

package.json specify exports.import as "./dist/index.mjs", but it doesn't appeared in the directory. That will cause webpack use non-exists file and complain Module not found: can't resolve "solid-resolve".
Looks like the mjs version is generated under the name "./dist/index.js" and the cjs version is under "./dist/index.cjs". A workaround to this in package.json:

 "exports": {
-    "require": "./dist/index.js",
+    "require": "./dist/index.cjs",
-    "import": "./dist/index.mjs",
+    "import": "./dist/index.js"
   },

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.