Nuxt Supabase
Getting started

Migration Guide

Learn how to migrate @nuxtjs/supabase to take advantage of JWT signing keys support

This guide will help you migrate from v1.x to v2.x, which introduces support for Supabase's new JWT signing keys.

🔐 What are JWT Signing Keys?

Supabase has introduced a major security improvement by moving from symmetric to asymmetric JWT (JSON Web Token) signing. This change brings security and performance improvements in how your applications handle authentication.

The Problem with Symmetric Keys

Previously, Supabase used a single shared secret key for both creating and verifying tokens. This meant your app had to constantly call supabase.auth.getUser() to check if sessions were valid, creating network delays calling the Supabase Auth server.

The Solution with Asymmetric JWT Signing Keys

The new system uses two separate keys:

  • A private key (kept secure by Supabase) for creating tokens.
  • A public key (safe to share in your application) for verifying them.

Your application can now verify user sessions locally without contacting Supabase servers, making it faster and more reliable. This new key is named as publishable key on Supabase.

Key Benefits

This upgrade eliminates authentication bottlenecks, improves security, and makes your applications work better at the edge (no extra calls to the Supabase Auth server).

Read the full technical explanation in the official Supabase blog post.

🚨 Breaking changes

1. useSupabaseUser Type Changes

useSupabaseUser now returns JWT claims instead of the full User object.

{
  id: "11111111-1111-1111-1111-111111111111",
  aud: "authenticated",
  role: "authenticated",
  email: "example@email.com",
  email_confirmed_at: "2024-01-01T00:00:00Z",
  phone: "",
  confirmed_at: "2024-01-01T00:00:00Z",
  last_sign_in_at: "2024-01-01T00:00:00Z",
  app_metadata: {},
  user_metadata: {},
  identities: []
}
If you need the full User object, you'll need to explicitly call auth.getUser() but if you only need basic info (email, role...) no changes are required.

2. Environment variables changes

Remaining keySUPABASE_KEY is now storing the publishable key instead of the anon key

New keySUPABASE_SECRET_KEY is now storing the secret key of your Supabase project

Deprecated keySUPABASE_SERVICE_KEY was previously storing the service_role key but is now deprecated in favor of SUPABASE_SECRET_KEY

📋 Migration Steps

1. Types changes

The first thing you need to do is to ensure the useSupabaseUser changes do not affect your existing code.

Once you've updated the types, you can already test your application and it should still work as expected.

2. Environment variables changes

The Good news ☀️ is that everything will continue to work as-is with your existing SUPABASE_KEY (aka anon key).

Same for SUPABASE_SERVICE_KEY, if you're using it to bypass Row Level Security, you will face a deprecation warning but it will still work.

However, we highly recommend you to enable JWT signing keys in your Supabase project and use your publishable key as SUPABASE_KEY and your secret key as SUPABASE_SECRET_KEY.

2.a. Enable JWT Signing Keys in Supabase Dashboard

Before migrating your environment variables, you need to enable JWT signing keys and thus create your JWT and API keys in your Supabase project:

Watch this video tutorial from 6:20 to 12:20 to understand how to enable JWT signing keys in your Supabase dashboard and get your new secret key.

2.b. Use your new keys in your .env file

.env
SUPABASE_KEY=<your_publishable_key>
SUPABASE_SECRET_KEY=<your_secret_key>