question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Authentication Error in NodeJS Integration

See original GitHub issue

I have recently come across SurrealDB, and installed it.

After adding to path, I started the server using surreal start --log trace --user root --pass root


 .d8888b.                                             888 8888888b.  888888b.
d88P  Y88b                                            888 888  'Y88b 888  '88b
Y88b.                                                 888 888    888 888  .88P
 'Y888b.   888  888 888d888 888d888  .d88b.   8888b.  888 888    888 8888888K.
    'Y88b. 888  888 888P'   888P'   d8P  Y8b     '88b 888 888    888 888  'Y88b
      '888 888  888 888     888     88888888 .d888888 888 888    888 888    888
Y88b  d88P Y88b 888 888     888     Y8b.     888  888 888 888  .d88P 888   d88P
 'Y8888P'   'Y88888 888     888      'Y8888  'Y888888 888 8888888P'  8888888P'


[2022-09-27 17:37:44] INFO  surrealdb::iam Root authentication is enabled
[2022-09-27 17:37:44] INFO  surrealdb::iam Root username is 'root'
[2022-09-27 17:37:44] INFO  surrealdb::dbs Database strict mode is disabled
[2022-09-27 17:37:44] INFO  surrealdb::kvs Starting kvs store in memory
[2022-09-27 17:37:44] INFO  surrealdb::kvs Started kvs store in memory
[2022-09-27 17:37:44] INFO  surrealdb::net Starting web server on 0.0.0.0:8000
[2022-09-27 17:37:44] INFO  surrealdb::net Started web server on 0.0.0.0:8000

In my NodeJS app, I have the following code (adapted from your docs):

import Surreal from 'surrealdb.js';
const db = new Surreal('http://localhost:8000/rpc');

async function main() {
	try {

		// Signin as a namespace, database, or root user
		await db.signin({
			user: 'root',
			pass: 'root',
            		NS: 'practice',
            		DB: 'buybig'
		});
        	console.log('y');

		// Select a specific namespace / database
		// await db.use('practice', 'buybig');

		console.log(await db.select('users'));

	} catch (e) {
		console.error('ERROR', e);
	}
}

main();

I am getting this error:

ERROR AuthenticationError: There was a problem with authentication
    at Surreal._Surreal_signin (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/index.js:416:23)    at Surreal.<anonymous> (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/index.js:225:111)   
    at Surreal.f (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/classes/emitter.js:28:18)     
    at file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/classes/emitter.js:34:22
    at Array.forEach (<anonymous>)
    at Surreal.emit (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/classes/emitter.js:33:67)  
    at Socket.<anonymous> (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/index.js:126:29)     
    at file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/classes/emitter.js:34:22
    at Array.forEach (<anonymous>)
    at Socket.emit (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/classes/emitter.js:33:67)   
^C

And this in my SurrealDB logs:

[2022-09-27 18:06:04] INFO  surreal::web 127.0.0.1:64675 GET /rpc HTTP/1.1 101 "-" 68.7µs

Accessing database through VSCode’s Thunder Client and SurrealDB cli tool works flawlessly.

Any help is appreciated.

Environment:

  • OS: Windows 10

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mathe42commented, Sep 27, 2022

You have to close the client! The DB connection is still alive!

1reaction
tobiemhcommented, Sep 27, 2022

Hi @JaiSh12345 to signin as a ‘root’ user don’t specify a NS or DB in the signin() method…

import Surreal from 'surrealdb.js';
const db = new Surreal('http://localhost:8000/rpc');

async function main() {
	try {

		// Signin as a root user
		await db.signin({
			user: 'root',
			pass: 'root',
		});
        	console.log('y');

		// Select a specific namespace / database
		await db.use('practice', 'buybig');

		console.log(await db.select('users'));

	} catch (e) {
		console.error('ERROR', e);
	}
}

main();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Authentication error in Node.js - Stack Overflow
I am trying to make a WebAPI call from server script and i am getting authentication error: This is how ...
Read more >
Authentication in Node.js - #5 Error Handling - YouTube
Authentication in Node.js - #6 Password Security · Mix - Code Realm · Error handling in sql server Part 56 · Using Clean...
Read more >
The Complete Guide to Node.js User Authentication with Auth0
This tutorial demonstrates how to secure a Node.js web application built with the Express framework by implementing user authentication.
Read more >
Failed to parse authentication message [#1236162] | Drupal.org
I am not using chatroom module currently. My current nodejs.config file looks like this: backendSettings = { 'scheme': 'http', 'host': 'hostname ...
Read more >
Exceptions | Node.js - Braintree Developer Documentation
braintree.exceptions.AuthenticationError. Raised when your API keys are incorrect. If you're getting this exception when first integrating, double-check ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found