serverSupabaseUser not working on server route when app is deployed to Netlify.
See original GitHub issueVersion
@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:
Any help provided will be appreciated. Thanks!
Issue Analytics
- State:
- Created a year ago
- Comments:9
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
Closing in favor of #101 (merging all Netlify issues)