Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: HTTPStrategy doesnt seem to remain authed after 1 hour #198

Open
2 tasks done
LucyEgan opened this issue Nov 27, 2023 · 1 comment
Open
2 tasks done

Bug: HTTPStrategy doesnt seem to remain authed after 1 hour #198

LucyEgan opened this issue Nov 27, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@LucyEgan
Copy link

LucyEgan commented Nov 27, 2023

Describe the bug

Having a surreal connection "open" with the HTTPStrategy will work fine for 1 hour as it was recently authed via /login, and returns a token that lives for 1 hour.
But then once using the "connection" for a hour with the first auth attempt the queries will start failing with

Failed to parse JSON
     at json (native)
     at processTicksAndRejections (:61:39) {   originalLine: 61,   originalColumn: 39 }

^^ Error from bun but from what I can see its a general issue for node too? But less likly to apply to node as the WebSocketStrategy works in node.

Steps to reproduce

let db = new ExperimentalSurrealHTTP();
await db.connect(config.host, {
    ns: config.namespace,
    db: config.database,
    auth: {
        user: config.username,
        pass: config.password,
        NS: config.namespace,
        DB: config.database,
    },
});

setInterval(async ()=>{
    console.log(new Date(), await db.query('RETURN 1'));
}, 1000);

After 1 hour it will fail with Failed to parse JSON

Expected behaviour

Either

  1. 5 minutes before the token expires it would reauth for a new token as the login details are still stored, either as a background task or at the point of use(and wait until reauthed)
  2. On auth failure of a query then reauth and reattempt.
  3. First handle it as method 1, but then also handle it safely as method 2 as well.

Out of the above I would say method 3.

SurrealDB version

1.0.0+20230913.54aedcd for linux on x86_64

SurrealDB.js version

0.11.0

Contact Details

lucy.e@aspirecomps.co.uk

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@LucyEgan LucyEgan added the bug Something isn't working label Nov 27, 2023
@LucyEgan
Copy link
Author

First auth attempt with username, password

await this.signin(auth);

Auth token is stored after successful login attempt

this.http?.setTokenAuth(res.token);

The point that there should be some handling of the now invalid token since I'm assuming its no longer valid json for "auth failed"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant