1.0.16 • Published 3 years ago

@amy-app/amy-app-js-sdk v1.0.16

Weekly downloads
182
License
-
Repository
-
Last release
3 years ago

Welcome to amy.app javascript SDK documentation

To use the amy.app SDK you need four main parts

  1. Create a new Amy app object const app = amy.initializeApp()
  2. Fetch an auth token from out api. https://api.amy.app/
  3. Log the user in await app.signInViaToken(<token>)
  4. Load an assignment amy. app.assignmentObserver(<assignmentId>, (assignment) => {})

Create a new Amy app object

The amy.app SDK works in tandem with Firebase. Make sure you load the firebase sdk as well as the amy.app sdk.

import firebase from "firebase";
import { initializeAmy, amyConfigs } from "@amy-app/amy-app-js-sdk";

After you have loaded both SDKs you can initialize Amy.app

const firebaseApp = firebase.initializeApp(amyConfigs, "amy.app");
const amy = initializeAmy({ firebaseApp });

In case you want to use multiple users on your webpage, you can add an optional name parameters when creating a firebase app.

const player1 = initializeAmy({
    firebaseApp: firebase.initializeApp(amyConfigs, "player1"),
});
const player2 = initializeAmy({
    firebaseApp: firebase.initializeApp(amyConfigs, "player2"),
});

Please keep in mind, each app needs an individual login. So if you want to same user use two app, you need to log this user in to each app.

Fetch an auth token from out api

To authenticate a user, you need to first create an auth token via our API (https://api.amy.app/).

To make development easier, we provide a swagger page on https://api.amy.app/ where you can copy-past your api-key. Furthermore, you can use the following example api_key during developent.

f25cc439c4a7aa8d7ea06f0d01e2b8116732a594b1547117dcc9641a91940823ed22b671ca07c56ea58f820bb2f0aa5ea74f612fc157a2761526e053fd493d0707f19216dcf7b24184c3da2970b7ad23f54f225c3be2612cf72bc6dfdd003ce898aaf0153cba8d2fb97caffc4f35bd718e7fd95f723341fdd83363ff34a48030

The token creating API can be founder under point /v2.0/auth/create-student-token . The following pictures show you how this should look like

Swagger page

After clicking Execute you should see a respone like this. You will notice the data.token is what you need

Swagger page

Production MODE

During production, you need to generate a token through a trusted server. The means your user need to send a request to your server. Your server sends a request to api.amy.app. api.amy.app respons with a token. And your server sends the token back to the user.

The full code could look like this

import firebase from "firebase";
import { initializeAmy, amyConfigs } from "@amy-app/amy-app-js-sdk"
const firebaseApp = firebase.initializeApp(amyConfigs, "amy.app");
const amy = initializeAmy({ firebaseApp });


if(!amy.user){
    // no user is signed in

    async function fetchToken(){
        const newToken = // fetch-token-from-you-server
        return newToken;
    }


    const token = await fetchToken();
    await amy.signInViaToken(<token>);
}

// user is logged in

Log the user in

To sign in the user, you need your app and token ready.

await amy.signInViaToken(<token>);

In case you want to check if a user already exists. For example when a user reloads the page, you can use

if(!amy.user){
    // no user is signed in
    await amy.signInViaToken(<token>);
}

// user is singed in
1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago