How to handle system-uri-response in the main.js process

This topic gave me the idea to authorise without using Electron, as I initially thought it’s a distraction.

I’ll just leave this minimal viable example here, in case anyone might deem it useful:

const safeApp = require('@maidsafe/safe-node-app');

const info = {
    id: 'example', name: 'example', vendor: 'example',
    customExecPath: [process.execPath, __filename],
};

async function authorise() {
    const app = await safeApp.initializeApp(info);
    const uri = await app.auth.genAuthUri({});
    await app.auth.openUri(uri.uri);
}

(async () => {
    if (process.argv.length == 2) {
        await authorise();
        process.exit();
    }

    const app = await safeApp.fromAuthURI(info, process.argv[2]);

    // Authenticated and ready to rumble
})();

Was a useful learning experience; haven’t tested it thoroughly yet. I understand now why Electron comes in handy as it manages the process and instance for you.

1 Like