[READ-ONLY] Mirror of https://github.com/danielroe/nuxt3-supabase. Nuxt 3 module and composables for Supabase.
0

Configure Feed

Select the types of activity you want to include in your feed.

TypeScript 83.2%
Vue 9.5%
JavaScript 5.3%
Other 2.0%
46 1 0

Clone this repository

https://git.vm.fail/danielroe.dev/nuxt3-supabase https://git.vm.fail/did:plc:jfn3fom7rt5obi74zyig3tjl
ssh://git@knot1.tangled.sh:2222/danielroe.dev/nuxt3-supabase ssh://git@knot1.tangled.sh:2222/did:plc:jfn3fom7rt5obi74zyig3tjl

For self-hosted knots, clone URLs may differ based on your setup.


README.md

nuxt3-supabase#

Nuxt 3 module and composables for Supabase.

Installation#

$ yarn add nuxt3-supabase
# or
$ npm install --save nuxt3-supabase

Getting Started#

Add the following to your nuxt.config.ts file.

export default defineNuxtConfig({
  modules: ['nuxt3-supabase/module'],
  supabase: {
    supabaseUrl: process.env.SUPABASE_URL,
    supabaseKey: process.env.SUPABASE_KEY
  },
  vite: false // temporary workaround for vite build errors
});

Usage#

<script setup lang="ts">
  const { $supabase } = useNuxtApp();

  const { data, pending } = await useAsyncData('posts', () => {
    return $supabase.from('posts').select();
  });
</script>

<template>
  <div v-if="pending">Loading...</div>
  <div v-else>{{ data }}</div>
</template>

Composables#

useSupabase#

Supabase client composable.

import { useSupabase } from 'nuxt3-supabase';

const supabase = useSupabase();

useAuth#

Supabase Auth composable.

import { useAuth } from 'nuxt3-supabase';

const { user, signIn, signOut } = useAuth();

useStorage#

Supabase Storage composable.

import { useStorage } from 'nuxt3-supabase';

const storage = useStorage();

useFrom#

Supabase Database composable.

import { useFrom } from 'nuxt3-supabase';

const from = useFrom();

useOnAuthStateChange#

Behaves similarly to onAuthStateChange but also sets/unsets auth cookie to the server.

import { useOnAuthStateChange } from 'nuxt3-supabase';

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

getServerSession#

Get the server session that was set by useOnAuthStateChange.

<script setup lang="ts">
  import { useOnAuthStateChange, getServerSession } from 'nuxt3-supabase';

  const nuxtApp = useNuxtApp();

  const { data } = await useAsyncData('user', () =>
    getServerSession(nuxtApp.ssrContext)
  );

  useOnAuthStateChange();
</script>

TIP: You can use getServerSession to check if a user is authenticated or not before route load.

TODO#

License#

MIT