surrealdb / surrealdb.js

SurrealDB SDK for JavaScript
https://surrealdb.com
Apache License 2.0
271 stars 46 forks source link

Bug: I'm getting error "The signup query failed" when trying to signup #283

Closed Nipodemos closed 2 weeks ago

Nipodemos commented 3 weeks ago

Describe the bug

I'm doing a simple project with NodeJS and trying to using surrealdb for the first time. However, everytime a use the db.signup() function, I get the errro mentioned in the title. I don't know if I am doing something wrong

Steps to reproduce

import { Surreal } from "surrealdb.js";

const db = new Surreal();

async function main() {
  try {
    // Connect to the database
    await db.connect("http://127.0.0.1:8000/rpc");

    await db.use({ namespace: "test", database: "test" });
    const values = {
      namespace: "test",
      database: "test",
      scope: "user",
      name: "John Doe",
      email: "nipodemos13@gmail.com",
      password: "123456",
    };

    console.log("values :>> ", values);
    const signupToken = await db.signup(values);
    console.log("signupToken :>> ", signupToken);
  } catch (e) {
    console.error("ERROR", e);
  }
}

main();
DEFINE TABLE user SCHEMAFULL PERMISSIONS FOR select,update WHERE id = $auth.id;
DEFINE FIELD name ON user TYPE string ASSERT string::len($value) > 2;
DEFINE FIELD email ON user TYPE string ASSERT string::len($value) > 2;
DEFINE FIELD password ON user TYPE string ASSERT string::len($value) > 2;

DEFINE SCOPE user
  SESSION 14d
  SIGNIN ( SELECT * FROM user WHERE email = $email AND crypto::argon2::compare(password, $password) )
  SIGNUP ( 
    CREATE user CONTENT {
      name: $nome,
      email: $email,
      password: crypto::argon2::generate($password)
    }
  );

Expected behaviour

Sign up successfully and return me a token

SurrealDB version

1.5.0 for windows on x86_64

SurrealDB.js version

1.0.0-beta.9

Contact Details

nipodemos13@gmail.com or a.lanzi@hotmail.com

Is there an existing issue for this?

Code of Conduct

kearfy commented 3 weeks ago

Hey @Nipodemos, you seem to be using a variable $nome in your signup query. Did you mean to use $name?

Nipodemos commented 3 weeks ago

What happened is that I was translating the code snippet to english since it was not in english originally but ended up forgetting that one variable. So in theory that's not the problem but now i need to double check just to be sure. I'll post it here when i'm done

Nipodemos commented 2 weeks ago

after many attempts, I've finally discovered the problem: the table name on the signup part was wrong. I admit i'm kinda feeling embarrassed right now, sorry for the trouble my friend