Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
How to import composables into server/api in Nuxt 3

I just unified a useSupabase composable to remove duplicate code and to have access to the supabase context.

But I get an error when I import the composable into the server/api folder:

message "useSupabase is not defined"

// composables/useSupabase.js
import { createClient } from '@supabase/supabase-js'
const useSupabase = () => {
  const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
  return {
    supabase
  }
}
export default useSupabase
// server/api/login.js
export default async (event) => {
  const body = await useBody(event)
  const { supabase } = useSupabase()

  const { user } = await supabase.auth.signUp({
    email: body.email,
    password: body.password
  })
  return user
}

Is there a way to import the composable into the endpoint?

another try

// server/api/logout.js
import { supabase } from '~/composables/useSupabase.js'

export default async () => {
  let { error } = supabase.auth.signOut()
  return error
}

another import suggested by Bo

// server/api/logout.js
import useSupabase from '~/composables/useSupabase.js'

export default async () => {
  const supabase = useSupabase()
  let { error } = supabase.auth.signOut()
  return error
} 

Error 500 "Cannot read property 'signOut' of undefined"

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is actually not Supabase related, it is Nuxt 3 currently doesn't support auto imports within the server directory, as Nuxt docs mentioned it here https://v3.nuxtjs.org/guide/concepts/auto-imports

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda