I am not sure even this is possible but I am trying to use Supabase with Node.js. I get the code from a React front-end, this link, which works okay.
Below is my code
client.js
const { createClient } = require('@supabase/supabase-js')
const supabaseUrl = "MY_URL"
const public_anon_key = "MY_ANON_KEY"
const supabase = createClient(supabaseUrl,public_anon_key)
exports.supabase = supabase
app.js
const { supabase } = require('./client')
async function signOut() {
/* sign the user out */
await supabase.auth.signOut();
}
async function signInWithGithub() {
/* authenticate with GitHub */
await supabase.auth.signIn({
provider: 'github'
});
}
async function printUser() {
const user = supabase.auth.user()
console.log(user.email)
}
signInWithGithub()
printUser()
signOut()
I am new to Node.js and I suspect something wrong with Promises is missing.
Is it possible to retrieve the user data from Supabase, if so, what is my code missing?
Thanks
Edit : title
I don't know what Supabase does but the problem seems to be Promise related
Try to change your app.js as follow
const { supabase } = require('./client')
function signOut() {
/* sign the user out */
supabase.auth.signOut();
}
function signInWithGithub() {
/* authenticate with GitHub */
return supabase.auth.signIn({
provider: 'github'
});
}
function printUser() {
const user = supabase.auth.user()
console.log(user.email)
}
signInWithGithub().then(() => {
printUser()
return signOut()
})