All Projects → nuxtclub → supabase

nuxtclub / supabase

Licence: MIT license
An easy way to integrate Supabase with NuxtJS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to supabase

nuxt-speedkit
nuxt-speedkit will help you to improve the lighthouse performance score (100/100) of your website.
Stars: ✭ 401 (+928.21%)
Mutual labels:  nuxt, nuxtjs, nuxt-module, nuxt-modules
cloudinary-module
Integration of Cloudinary to Nuxt.js
Stars: ✭ 129 (+230.77%)
Mutual labels:  nuxtjs, nuxt-module, nuxt-modules
applicationinsights-module
Application Insights module for NuxtJS
Stars: ✭ 14 (-64.1%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-typo3
TYPO3 Frontend rendered in Vue.js and Nuxt (frontend for EXT:headless)
Stars: ✭ 66 (+69.23%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-humans-txt
🧑🏻👩🏻 "We are people, not machines" - An initiative to know the creators of a website. Contains the information about humans to the web building - A Nuxt Module to statically integrate and generate a humans.txt author file - Based on the HumansTxt Project.
Stars: ✭ 27 (-30.77%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
k-domains
A simple module to manage multiple subdomains with just one project
Stars: ✭ 41 (+5.13%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-ghost
Easy Ghost content API integration with Nuxt.js.
Stars: ✭ 27 (-30.77%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
isnuxt3ready
A community-built compatibility guide for Nuxt 3 modules
Stars: ✭ 106 (+171.79%)
Mutual labels:  nuxt, nuxtjs, nuxt3
nuxt-ts-module
A tiny module to use Typescript within Nuxt.js application.
Stars: ✭ 21 (-46.15%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt
Nuxt 3 and Vue 3 client for genealogy project. Family tree and genealogy data processing website software client.
Stars: ✭ 97 (+148.72%)
Mutual labels:  nuxt, nuxtjs, nuxt3
nuxt-modules
AX2's Nuxt modules
Stars: ✭ 30 (-23.08%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
global-components
Module to register global components for Nuxt.js
Stars: ✭ 57 (+46.15%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-feature-toggle
The nuxt feature toggle module
Stars: ✭ 78 (+100%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-babel
Use normal .babelrc file with your Nuxt app
Stars: ✭ 32 (-17.95%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-quasar
Nuxt module for the Quasar Framework
Stars: ✭ 36 (-7.69%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-gsap-module
GSAP module for Nuxt.js
Stars: ✭ 183 (+369.23%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
date-fns-module
Modern JavaScript date utility library - date-fns for Nuxt.js
Stars: ✭ 68 (+74.36%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
separate-env-module
Tear your variables apart!
Stars: ✭ 53 (+35.9%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
vue-plausible
Plausible Analytics Vue.js Plugin and NuxtJS Module
Stars: ✭ 107 (+174.36%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
lumen-cms
GraphQL API-First CMS based on NodeJS and Vue 2, Nuxt and Vuetify
Stars: ✭ 77 (+97.44%)
Mutual labels:  nuxt, nuxtjs, nuxt-module

@nuxtclub/supabase

Setup

  1. Add @nuxtclub/supabase dependency to your project
npm i -D @nuxtclub/supabase
  1. Add @nuxtclub/supabase to the buildModules section of nuxt.config.js

⚠️ If you are using Nuxt < v2.9 you have to install the module as a dependency (No --dev or --save-dev flags) and use modules section in nuxt.config.js instead of buildModules.

export default {
	buildModules: [
		[
			'@nuxtclub/supabase',
			{
				/* module options */
			},
		],
	],
}

Using top level options

export default {
	buildModules: ['@nuxtclub/supabase'],
	supabase: {
		/* module options */
	},
}

Typescript support

Add the types to your "types" array in tsconfig.json after the @nuxt/types entry.

⚠️ Use @nuxt/vue-app instead of @nuxt/types for nuxt < 2.9.

{
	"compilerOptions": {
		"types": ["@nuxt/types", "@nuxtclub/supabase"]
	}
}

Configuration

To start using Supabase in your project you should place the URL and the public API KEY of your Supabase project.

You can find this data on the administration panel of your project > Settings > API.

Be sure to copy your public key, not your private key.

export default {
	supabase: {
		url: 'YOUR_SUPABASE_URL',
		key: 'YOUR_SUPABASE_KEY',
	},
}

Usage

This module will inject $supabase in the context of your application.

Using $supabase you can access to the SupabaseClient object of the Supabase Client for JavaScript.

Shortcuts

This module also inject $supaAuth & $supaStorage that are nothing more than a shorcut for $supabase.auth and $supabase.storage.

Examples

Fetching data

<template>
	<div>
		<h1>Recipes</h1>
		<ul>
			<li v-for="recipe in recipes" :key="recipe.id">
				{{ recipe.name }}
			</li>
		</ul>
	</div>
</template>

<script>
export default {
	middleware: 'authenticated',
	async asyncData({ $supabase }) {
		const { data } = await $supabase.from('recipes').select('*')
		return { recipes: data }
	},
}
</script>

Authentication:

Create a page to sign in:

<!-- ~/pages/sign-in -->
<template>
	<form @submit.prevent="submit()">
		<input type="email" v-model="email" />
		<input type="password" v-model="password" />
		<button type="submit">Sign In</button>
	</form>
</template>

<script>
export default {
	data() {
		return {
			email: '',
			password: '',
		}
	},
	methods: {
		submit() {
			this.$supabase.auth
				.signIn({
					email: this.email,
					password: this.password,
				})
				.then(({ error, data }) => {
					if (error) {
						alert(error.message)
					} else {
						this.$router.push('/')
					}
				})
		},
	},
}
</script>

To make the sign up page copy the same code and change the signIn function by signUp.

Create a Middleware to protect your routes:

// ~/middleware/authenticated.js
export default ({ $supabase, redirect }) => {
	if (!$supabase.auth.session()) {
		return redirect('/sign-in')
	}
}

Protect the home page using previously created middleware.

<!-- ~/pages/index.vue -->
<template>
	<div>
		<h1>You're authenticated!</h1>
		<button @click="signOut()">Sign Out</button>
	</div>
</template>

<script>
export default {
	middleware: 'authenticated',
	methods: {
		signOut() {
			this.$supabase.auth.signOut().then(({ error }) => {
				if (error) {
					console.error(error)
				} else {
					this.$router.push('/sign-in')
				}
			})
		},
	},
}
</script>

Learn more about Supabase here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].