Skip to content

Wasm-Client does not allow token corrections (I belive) #67

@gropaul

Description

@gropaul

Hi dear MotherDuck team,

I am struggling to reauthenticate to Motherduck after entering an incorrect token.

The workflow is the following:

  1. I want to connect to MD
  2. I prompt the user to input his/her MD token
  3. The user gives a wrong token. I try to connect with MDConnection.create. It fails as expected.
  4. I tell the user to enter a correct token
  5. The user gives a correct token
  6. I again try to connect with MDConnection.create. It fails unexpectedly

I saw in the docs that Multiple connections can be created. Connections share a DuckDB Wasm instance, so creating subsequent connections will not repeat the initialization process. Link

I can't close the connection as I can't get a working connection instance :(

This leads to the following unexpected behaviours:

  1. Creating a connection with a wrong token and then with a correct one leads to both connections not working
  2. Creating a connection with a right token and then with a wrong one still lets the 2nd one work
try {
    const fakeToken = 'invalid'
    const testConnection = MDConnection.create({
        mdToken: fakeToken
    });

    const isInitialized = await testConnection.isInitialized();
    console.log('Fake Token Initialized: ', isInitialized);
    const versionResult = await testConnection.evaluateQuery("select version();");
    const version = versionResult.data.singleValue();
    console.log('Fake Token Motherduck version: ', version);
} catch (e) {
    console.log('Fake token failed as expected. Error: ', (e as Error).message); <- This will be executed as expected
}

try {
    const actualToken = 'actual_correct_token '
    const testConnection = MDConnection.create({
        mdToken: actualToken
    });
    const isInitalized = await testConnection.isInitialized();
    console.log('Real Token Initialized: ', isInitalized);
    const versionResult = await testConnection.evaluateQuery("select version();");
    const version = versionResult.data.singleValue();
    console.log('Real Token Motherduck version: ', version);
} catch (e) {
    console.log('Real token failed. Error: ', (e as Error).message); <- It will still throw the unauth error here unexpected
}


try {
    const actualToken = 'actual_correct_token '
    const testConnection = MDConnection.create({
        mdToken: actualToken
    });
    const isInitalized = await testConnection.isInitialized();
    console.log('Real Token Initialized: ', isInitalized);
    const versionResult = await testConnection.evaluateQuery("select version();");
    const version = versionResult.data.singleValue();
    console.log('Real Token Motherduck version: ', version);   <- This is called as expected
} catch (e) {
    console.log('Real token failed. Error: ', (e as Error).message);
}

try {
    const fakeToken = 'invalid'
    const testConnection = MDConnection.create({
        mdToken: fakeToken
    });

    const isInitialized = await testConnection.isInitialized();
    console.log('Fake Token Initialized: ', isInitialized);
    const versionResult = await testConnection.evaluateQuery("select version();");
    const version = versionResult.data.singleValue();
    console.log('Fake Token Motherduck version: ', version);    <- This is still working, but should not
} catch (e) {
    console.log('Fake token failed as expected. Error: ', (e as Error).message);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions