badcodeltd / safecms

A powerful content management system built on top of the SAFE Network
MIT License
14 stars 5 forks source link

Using Safe-CMS with Safe Browser mock routing - does not authenticate #25

Open JPL1 opened 6 years ago

JPL1 commented 6 years ago

I don't think this will be much of an issue for many people as they won't be using mock routing to develop a website, but I was curious to see if it would work as I'm running out of credits on my Alpha2 account.

Trying this in Windows 10.

Open Safe Browser MR first and login, Open Safe-CMS - appears to authenticate in browser but hangs on opening screen "Waiting to Authenticate" Is there a config file that needs changing?

Safe CMS console:

C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\src\safe\index.js:56 Uncaught (in promise) Emessage: "Unexpected (probably a logic error): Could not connect to the SAFE Network"stack: "-2000↵    at module.exports (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\@maidsafe\safe-node-app\src\native\_error.js:19:10)↵    at ffi.Callback (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\@maidsafe\safe-node-app\src\native\_app.js:63:22)↵    at C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\ffi\lib\callback.js:66:25↵    at Function.proxy (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\ffi\lib\_foreign_function.js:59:14)↵    at Promise (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\@maidsafe\safe-node-app\src\native\_app.js:72:14)↵    at Promise (<anonymous>)↵    at Object.app_registered (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\@maidsafe\safe-node-app\src\native\_app.js:59:16)↵    at lib.decode_ipc_msg.then (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\@maidsafe\safe-node-app\src\api\auth.js:330:22)↵    at <anonymous>"__proto__: Error
    at makeError (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\@maidsafe\safe-node-app\src\native\_error.js:10:17)
    at module.exports (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\@maidsafe\safe-node-app\src\native\_error.js:18:13)
    at ffi.Callback (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\@maidsafe\safe-node-app\src\native\_app.js:63:22)
    at C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\ffi\lib\callback.js:66:25
    at Function.proxy (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\ffi\lib\_foreign_function.js:59:14)
    at Promise (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\@maidsafe\safe-node-app\src\native\_app.js:72:14)
    at Promise (<anonymous>)
    at Object.app_registered (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\@maidsafe\safe-node-app\src\native\_app.js:59:16)
    at lib.decode_ipc_msg.then (C:\Users\user\Documents\safe-cms-0.0.6-windows\resources\app\node_modules\@maidsafe\safe-node-app\src\api\auth.js:330:22)
    at <anonymous>
BadCodeAndy commented 6 years ago

I believe the problem lies here: https://github.com/badcodeltd/safecms/blob/master/src/safe/index.js#L43

Essentially, despite the browser being compiled for mock routing, the production application still believes it is running in a production environment because node isn't passing a NODE_ENV value of dev.

As such, loginForTest is never run, and it tries to authenticate with the production environment (and, presumably, gets an invalid authentication code as a result).

I think the correct solution here is to allow the user to add a mock.flag file in the project route which will tell the executable to use mock routing (essentially, if mock.flag is there, add a fake dev NODE_ENV to the running Node process.)

BadCodeShane commented 6 years ago

It's a good approach and solves the problem, but I've thought about it and would rather do it like this:

Rather than requiring a user to create a file, we could add it as a setting, the latest commits allow the creation of generic yes/no setting options, so adding this would be trivial. If the user sets "Use Mock routing" to true, re-start the app and re-authenticate with the mock routing network code.

I just don't like the idea of splitting the settings up between the GUI and the file system.