"APP ZERO": Beginners SAFE Web App Tutorial

Thanks! Just put all your work into an APP ZERO TEST10 repo, and updated the OP

3 Likes

prob add a welcome.html so the redirect works also :wink:

I’m trying to get my welcome.html to getdns and display my username next.

No idea

6 Likes

I just uploaded the test 10 repo code and tried to give it a shot, but no luck getting its /auth to work with Launcher…

safe://appzero.whiteout/

TEST 10 Link^

2 Likes

Try this: https://github.com/aenemic/safe-api-tests/blob/master/authtest.js

1 Like

ok looks good, I just reuploaded and remapped the SAFE DNS so now mine works with that code:

safe://appzero.whiteout/

TEST 10 Link^

I just need to refine the code and make it smaller so it can go inside the APP ZERO TEST10 repo

2 Likes

#APP ZERO now exists in Python also!

10 Likes

Working on the first APP ZERO attempt that works with the SAFE Beaker Browser / safe-js, no success so far, looking for help from anyone (including @joshuef )

Page loads up locally, looks fine, but this js file is where the problems are. I tried combining the code from the original version (built around FFox proxy) and code from the safe-js Github readme.md where it gives the Auth example.

The whole point of this is to just make the Auth command work with safe-js and SAFE Beaker Browser. Any and all help very much appreciated!

1 Like

try this:

let app = {
       name: 'your_app_name',
       id: 'your_app_id',
       version: '0.0.1',
       vendor: 'you',
       permissions: [],
      }

    window.safeAuth.authorise(app).then(function(success_text) {
        console.log("SUCCESS:" + success_text);
    }).catch(function(error_text) {
        console.log("ERROR:" + error_text);
    });

Protip: in the developer tools of Beaker (view -> Toggle DevTools) in the “Console” section. You can type javascript code directly inside the console. Type “window.safe” to see the Safe API exposed by the browser.

4 Likes

I’ve just updated the readme now, which should clarify some things, as well as updating the outdated initial example.

So safe-js can be used in node, or any browser, and that would use methods as listed in the readme.

However, when using the SAFE Browser, these methods are baked into the window object, which means 1) they run internally in the background in beaker, and 2) you dont need to include your own copy of safe-js, they are automatically (and only) available to safe: sites.

So your example here, when uploaded to the network, should look like:

const app =
{
    name: "name",
    id: "id",
    version: "v",
    vendor: "vendor_name",
    permissions: ["SAFE_DRIVE_ACCESS"]
};

window.safeAuth.authorise( app );

Before uploading to the neteork, you’ll need to test these same methods, which is why there’s a window.safeX polyfill available in the npm package. As described over here.

Hope that’s helpful

6 Likes

Hey this is awesome, I tried ctrl+j/k and gave up after that lol. Glad to know it exists! Will be a great help

1 Like

In beaker it is Ctrl-Alt-I

1 Like

Is that code you supplied supposed to work in the console? It looks like the window function of “authorise” can’t work that way, is this what @joshuef was talking about for the “polyfill” thing (which I’m still not quite clear on what it is)?

I’m guessing not, and will try it in a hosted SAFE page now

Thanks for helping me along, still can’t seem to get it to work though. This is my newest javascript attempt, and it is all running from SAFE (at this Alphanet link safe://appzerosafejs.bigbang/) and my dev console keeps saying “unexpected token import” even though I’ve removed all the LOCAL_TOKEN etc code. Not sure what to make of it here. Just trying to learn the flow of safe-js’s tools

1 Like

So, I can’t see the site with the 0.9.2 launcher. Data doesn’t exist.

But it looks like you’re trying to run javascript es6 import code directly in the browser, where import rules will not work.

If you are trying to run these lines in the browser, that’s your import error.

Your safejs code looks good in itself (and as you note, with the latest version of the browser/safejs, you don’t need to supply a token as it will be overridden by the url of the site in beaker anyway).

So to get this code running, I think you only need remove those two lines.

1 Like

He’s on “Alphanet” so probably not Test 11 / Launcher 0.9.2.

3 Likes

That’s right, I haven’t updated my apps. SafeLauncher is 0.8.0, Safe browser is 0.2.7.

@whiteoutmashups you can see an example of the code here: safe://simplesafe2.davidmtl/ on alpha. Note that it’s not fully functional but the authorization part works.

2 Likes

All that worked great in the console (0.3.6-2) so thanks for that! but still can’t get a SAFE hosted version to work.

Made another APP ZERO attempt, trying to finally get a safe-js / beaker version of A0 to work.

(testable on Alpha at safe://a0sjs.wom/)

I must be doing something wrong? I know there have been changes made to how tokens are used @joshuef @happybeing do you think this has anything to do with APP ZERO never working in safe-js yet?

2 Likes

WELL DONE mate great to see!!!

1 Like

Python version seems to be missing (dead link).

Hmm I’ll get this fixed and synced

EDIT: Not sure what you mean, this is the link and it’s working fine for me, showing up correctly on github, can see all the python code right there