Supabase Auth features are like a God's gift from heaven for having a record-speed authentication system ready to go for your side projects whenever you need.
However, since @supabase/supabase-js
up to v2 (at time of writing) is meant for JAMstack developers, it does take some additional configuration to use it for the Node.js environment.
You will need to some additional configuration:
// ANON_KEY and ANON_URL are string constants from your project
createClient(ANON_URL, ANON_KEY, {
auth: { persistSession: false, autoRefreshToken: false },
})
This will disable attempts by the client to store and refresh session, as there is no localStorage in server/scripting environments.
Your API calls will now work flawlessly 🔥.
Shoutout to Kang Ming and Alaister for this, my awesome colleagues at Supabase, whose deep knowledge of the client during a discussion in Bali Nov 2022 led to the above snippet.