so, im trying to get a column from a table that's ...
# help
c
so, im trying to get a column from a table that's selected
Copy code
js
async function user_salt(user) {
  let database = await supabase
    .from("user")
    .select("user_salt")
    .eq("email", user.email);

    return database.user_salt;
}
but its returning a Promise
n
Hello @CipherCode! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
🆕 returning promise instead of column
s
It's likely to be returning an array of objects, since you didn't qualify it with
.single()
or
.maybeSingle()
n
returning promise instead of column
c
okay, i just set it to single() and its still saying Promise when i console.log(database.user_salt);
thank you for your hepl btw
help
should i post full code?
Copy code
js
const supabase = createClient(
  "https://vxjkjerxycfkqrlvtidc.supabase.co",
);
async function user_salt(user) {
  let database = await supabase
    .from("user")
    .select("user_salt")
    .eq("email", user.email).single();

    return database.user_salt;
}
async function create_account(user,ws) {
  let user_salt = Math.floor(Math.random() * 999999);
  await supabase.from("user").insert([
    {
      user_salt: user_salt,
      email: user.email,
      first_name: user.first_name,
      last_name: user.last_name,
      password: Utility.encrypt_password(
        user.password1,
        user_salt
      ),
      last_four: user.last_four,
      mailing_address: user.mailing_address,
    },
  ]);
  ws.send("Account Created");
}
function login(user, ws) {  
  let user_db =  supabase
  .from("user")
  .select("password")
  .eq("email", user.email);
  console.log(user_salt(user));
  if ( user_db.password == Utility.encrypt_password(user.password,user_salt(user))) {
    ws.send("Correct Password");
  } else 
    ws.send("Incorrect Password");
}
am i supposed to await every supabase call?
s
Yes. Every function marked as
async
needs to be called with
await
, otherwise a promise is returned instead.
c
ohh
maybe this is a javascript question more than a supabase question
sorry about that
g
@CipherCode even when you sort that you will have an issue in that database = await supabase..... is going to return an complex object with error,data, status,etc. You will then need to use database.data.user_salt if you use .single(). Normally you will see in the guides using const {data,error} = await ... to pull out the data object directly.
c
Nice!! Thank you