question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

serverSupabaseUser not working on server route when app is deployed to Netlify.

See original GitHub issue

Version

@nuxtjs/supabase: “^0.1.25” nuxt: “^3.0.0-rc.11”

Issue

I’m trying to deploy my Nuxt 3 app which renders client side to Netlify and locally, Supabase Auth works as intended.

However, upon deploying the app to Netlify, when I call server routes that needs user validation, suddenly the serverSupabaseUser returns undefined even though the user is logged in since a session was obtained from Supabase.

I’m wondering whether I did something wrong on my end or if I’m missing something.

nuxt.config.js

import { defineNuxtConfig } from 'nuxt/config';

export default defineNuxtConfig({
  ssr: false,
  target: 'static',
  modules: [
    '@nuxtjs/supabase',
    ...
  ],
  ...
});

server/api/profile.get.js

import { serverSupabaseUser } from '#supabase/server';
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

export default defineEventHandler(async (event) => {
  const user = await serverSupabaseUser(event);
  if (!user) {
    throw new Error('Not authorized');
  }

  const profile = await prisma.profiles.findUnique({
    where: {
      id: user.id,
    },
  });
  return profile;
});

pages/login.vue

async function login() {
  const { error } = await client.auth.signIn({
    email: email.value,
    password: password.value,
    initialCache: false,
  });
  if (error) $toast(error.message, 'error');

  $toast('Successfully logged in!', 'success');
  const { data: profile } = await useFetch('/api/profile');
  store.setProfile(profile.value);
}

Fetch result: image

Any help provided will be appreciated. Thanks!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
larbishcommented, Sep 23, 2022

Indeed, I’ve reproduced it here: https://github.com/larbish/nuxt3-supabase-with-server-routes. Don’t know what’s going on with Netlify, need to dig into it. However, as a temporary fix you can deploy on Vercel as it is working as expected, you can check it here: https://nuxt3-supabase-with-server-routes-6ki7.vercel.app

0reactions
larbishcommented, Oct 27, 2022

Closing in favor of #101 (merging all Netlify issues)

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Route params not working after deployment - Support
Anyone can open their browser dev tools and view them, and of course this can lead to someone abusing this access. In some...
Read more >
How to Deploy a React Router App to Netlify and Fix the ...
This article has explained how to deploy a react-router app using Netlify's CLI and fix the page-not-found error while accessing your routes. I ......
Read more >
API not working after deploying on netlify. I'm using a proxy ...
Make sure you have not pushed your .env file to GitHub (in case you have it) because this might be the case of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found