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

@jambff/ra-supabase-next-auth

v2.1.2

Published

Integrate [React Admin](https://marmelab.com/react-admin/) with [Supabase Auth](https://supabase.com/auth) for [Next.js](https://nextjs.org/) applications.

Downloads

39

Readme

React Admin Supabase Next Auth

Integrate React Admin with Supabase Auth for Next.js applications.

Installation

yarn add @jambff/ra-supabase-next-auth

Also be sure to install all peer dependencies.

Setup

In your Supabase project settings go to Authentication > URL Configuration and add /auth to your "Site URL", for example:

http://my.site.com/auth

Add a file to your Next.js pages folder at pages/auth.ts containing the following:

import { AuthPage } from '@jambff/ra-supabase-next-auth';

export default AuthPage;

Or, if you are using a custom basename to serve your admin pages:

import { AuthPage } from '@jambff/ra-supabase-next-auth';

const Page = () => <AuthPage basename="/admin" />;

export default Page;

Set the authProvider and loginPage in your React Admin App.tsx component, like so:

import { FC } from 'react';
import { Admin } from 'react-admin';
import { createClient } from '@supabase/supabase-js';
import { LoginPage, createAuthProvider } from '@jambff/ra-supabase-next-auth';

const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY);
const authProvider = createAuthProvider(supabase);

const App: FC = () => (
  <Admin
    authProvider={authProvider}
    loginPage={LoginPage}
  >
    <Resource
      name="my-stuff"
    />
  </Admin>
);

export default App;

Authentication

The authentication process will add an access_token cookie that can be used in any subsequent requests that require authentication.

The @jambff/supabase-auth-fetch package can be used to generate a fetch client the uses this token.

Identity

By default this library will create user identity objects with an id and fullName, which is populated with the user's email.

If you have additional user data in a separate Supabase table you can merge this into the user's identity object by passing in a getIdentity() function when creating the auth provider, for example:

import { createClient, User } from '@supabase/supabase-js';
import { createAuthProvider } from '@jambff/ra-supabase-next-auth';

const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY);
const authProvider = createAuthProvider(supabase, {
  getIdentity: async (supabaseUser: User) => {
    const { data, error } = await supabase
      .from('User')
      .select('name, role')
      .eq('guid', supabaseUser.id);

    const { name, role } = data?.[0] ?? {};
    const { id, email } = supabaseUser;

    return {
      id,
      fullName: name ?? email,
      email,
      role,
    };
  },
});

The data you return will be attached to the profile attribute of the user's identity object.

Roles

If the object you return from your custom getIdentity() function includes a role property the value of this property will be made available via React Admin's usePermissions() hook (see Permissions).

Additionally, if you pass in an acceptedRoles property when creating the auth provider only users with those roles will be allowed in, for example:

import { createClient, User } from '@supabase/supabase-js';
import { createAuthProvider } from '@jambff/ra-supabase-next-auth';

const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY);
const authProvider = createAuthProvider(supabase, {
  acceptedRoles: ['admin', 'editor'],
  getIdentity: async (supabaseUser: User) => {
    // Get real identity
    return { role: 'admin' };
  },
});