<#843999948717555735> I have a problem with next.j...
# help
r
#843999948717555735 I have a problem with next.js/SSR and Supabase. I am following the next.js starter tutorial but I wanted to load the profile before the page render. To achieve that I moved the respective code under api/
Copy code
export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  const user = await supabase.auth.user();
  const { data, error, status } = await supabase
    .from("profiles")
    .select(`username, country, avatar_url`)
    .eq("id", user?.id)
    .single();

  if (error) return res.status(status).json({ error: error.message });
  return res.status(200).json({ user: data });
}
However, I am getting an error response
Copy code
error: "invalid input syntax for type uuid: \"undefined\""
Can't I reach logged in user's id inside the API folder?
g
This is all auth.user() does from the code: /** * Inside a browser context,
user()
will return the user data, if there is a logged in user. * * For server-side management, you can get a user through
auth.api.getUserByCookie()
*/ user(): User | null { return this.currentUser }
So you don't have a user set up yet.
r
Is there a complete example somewhere? I dont think adding just that getUserByCookie makes it work
g
I'm sorry, I can't help there I use sveltekit in static only so no server stuff. You could search here or supabase github discussion on SSR or getStaticProps(similar problem for people using it) or maybe even getUserByCookie. I know there are conversations, not sure about answers... It must work though as the code is there for it.
r
g
😲