npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nuxt-supabase-user-attributes

v1.0.4

Published

[![Npm package version](https://badgen.net/npm/v/nuxt-editorjs)](https://npmjs.com/package/nuxt-supabase-user-attributes) [![Npm package total downloads](https://badgen.net/npm/dt/nuxt-editorjs)](https://npmjs.com/package/nuxt-supabase-user-attributes) [!

Downloads

4

Readme

nuxt-supabase-user-attributes

Npm package version Npm package total downloads MIT license

Persistent user attributes with Supabase and Nuxt.

Introduction

This module extends the @nuxtjs/supabase module to allow for user attribute tables (such as profiles and metadata) to be used in a Nuxt3 application with a similar interface to useSupabaseUser() via a single composable:

<script setup>
  const {metadata, profile} = useSupabaseUserAttributes(); 
  if(metadata.role != "admin") {navigateTo("/")}
</script>

Setup and Installation

This module requires a Supabase DB with one or more user attribute tables. Each of these tables must have a column referencing auth.users.id. See /supabase/migrations/0_users_profiles.sql for an example of two such user attribute tables, complete with Postgres triggers and row level security policies. Once the database has been set up (and started if running locally), add a SUPABASE_URL and SUPABASE_KEY to a .env file. Next, follow the steps below:

  • Install the Supabase module: yarn add @nuxtjs/supabase
  • Install the use attributes module: yarn add nuxt-supabase-user-attributes
  • Add both modules to your nuxt.config.ts file:
export default defineNuxtConfig({
  ...
  modules: ["nuxt-supabase-user-attributes", "@nuxtjs/supabase"],
  supabaseUserAttributes: {
    tables: [
      {
        name: "user_metadata",
        alias: "metadata",
        user_id_column: "id",
        multiple: false,
      }
    ]
  },
  ...
});

supabaseUserAttributes.tables defines an array tables with the following variables:

  • name: The name of the user attribute table. (required)
  • alias: An alias used to reference the attribute. (optional: defaults to the table name)
  • user_id_column: The column of the user attribute table which references auth.users.id. (optional: defaults to 'id')
  • multiple: Whether to return the user attributes as an array or single element. (optional: defaults to false)

For example, the following configuration:

supabaseUserAttributes: {
  tables: [
    {
      name: "user_metadata",
      alias: "metadata",
      user_id_column: "id",
      multiple: false,
    },
  ];
}

Allows for the current user's metadata to be accessed at any point in the application (both client and server-side) using the following composable:

const { metadata } = useSupabaseUserAttributes();

Development

We include a development playground with an example database schema able to be initialised locally with the Supabase CLI (supabase start). This example includes two example users ([email protected] and [email protected] - both using the password 12345678) with different roles and privileges as defined in /supabase/migrations/0_users_profiles.sql. Once the local database is running, use yarn to develop and build the module:

  • Run yarn to install required dependencies.
  • Run yarn dev:prepare to generate type stubs.
  • Use yarn dev to start playground in development mode.
  • Use yarn prepack to build the module.