summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichiel Schuurmans <michielschuurmans@gmail.com>2020-10-27 21:25:42 +0100
committerMichiel Schuurmans <michielschuurmans@gmail.com>2020-10-27 21:25:42 +0100
commit85621b93ecc74efe330dad1478b3414016baaad6 (patch)
tree82ce83f484642d2294ba4a3535530833e16f407e
parentd8ed3ce56cffa560452b0592a3e1f036c36c5135 (diff)
Add notes
Signed-off-by: Michiel Schuurmans <michielschuurmans@gmail.com>
-rw-r--r--NOTES16
-rw-r--r--web/src/auth/index.js202
2 files changed, 117 insertions, 101 deletions
diff --git a/NOTES b/NOTES
new file mode 100644
index 0000000..614220c
--- /dev/null
+++ b/NOTES
@@ -0,0 +1,16 @@
+=== WEB ===
+
+The api access token isn't stored in the browser. So when a page is closed and
+you want to start / stop the blender you have to login again. This can be
+problematic when you want to stop de blender from blending.
+
+TODO:
+store access token in local storage
+
+=== API ===
+
+On the the machine in the same network as the plc the queue has to be ran with
+the following command 'php artisan queue:listen --sleep 0'. The sleep is set to
+0 because we want to be able to act fast when a new action is requested.
+
+=== Modbus ===
diff --git a/web/src/auth/index.js b/web/src/auth/index.js
index 4138440..35afc67 100644
--- a/web/src/auth/index.js
+++ b/web/src/auth/index.js
@@ -3,7 +3,7 @@ import createAuth0Client from "@auth0/auth0-spa-js";
/** Define a default action to perform after authentication */
const DEFAULT_REDIRECT_CALLBACK = () =>
- window.history.replaceState({}, document.title, window.location.pathname);
+ window.history.replaceState({}, document.title, window.location.pathname);
let instance;
@@ -12,116 +12,116 @@ export const getInstance = () => instance;
/** Creates an instance of the Auth0 SDK. If one has already been created, it returns that instance */
export const useAuth0 = ({
- onRedirectCallback = DEFAULT_REDIRECT_CALLBACK,
- redirectUri = window.location.origin,
- ...options
+ onRedirectCallback = DEFAULT_REDIRECT_CALLBACK,
+ redirectUri = window.location.origin,
+ ...options
}) => {
- if (instance) return instance;
+ if (instance) return instance;
- // The 'instance' is simply a Vue object
- instance = new Vue({
- data() {
- return {
- loading: true,
- isAuthenticated: false,
- user: {},
- auth0Client: null,
- popupOpen: false,
- error: null
- };
- },
- methods: {
- /** Authenticates the user using a popup window */
- async loginWithPopup(o) {
- this.popupOpen = true;
+ // The 'instance' is simply a Vue object
+ instance = new Vue({
+ data() {
+ return {
+ loading: true,
+ isAuthenticated: false,
+ user: {},
+ auth0Client: null,
+ popupOpen: false,
+ error: null
+ };
+ },
+ methods: {
+ /** Authenticates the user using a popup window */
+ async loginWithPopup(o) {
+ this.popupOpen = true;
- try {
- await this.auth0Client.loginWithPopup(o);
- } catch (e) {
- // eslint-disable-next-line
- console.error(e);
- } finally {
- this.popupOpen = false;
- }
+ try {
+ await this.auth0Client.loginWithPopup(o);
+ } catch (e) {
+ // eslint-disable-next-line
+ console.error(e);
+ } finally {
+ this.popupOpen = false;
+ }
- this.user = await this.auth0Client.getUser();
- this.isAuthenticated = true;
- },
- /** Handles the callback when logging in using a redirect */
- async handleRedirectCallback() {
- this.loading = true;
- try {
- await this.auth0Client.handleRedirectCallback();
- this.user = await this.auth0Client.getUser();
- this.isAuthenticated = true;
- } catch (e) {
- this.error = e;
- } finally {
- this.loading = false;
- }
- },
- /** Authenticates the user using the redirect method */
- loginWithRedirect(o) {
- return this.auth0Client.loginWithRedirect(o);
- },
- /** Returns all the claims present in the ID token */
- getIdTokenClaims(o) {
- return this.auth0Client.getIdTokenClaims(o);
- },
- /** Returns the access token. If the token is invalid or missing, a new one is retrieved */
- getTokenSilently(o) {
- return this.auth0Client.getTokenSilently(o);
- },
- /** Gets the access token using a popup window */
+ this.user = await this.auth0Client.getUser();
+ this.isAuthenticated = true;
+ },
+ /** Handles the callback when logging in using a redirect */
+ async handleRedirectCallback() {
+ this.loading = true;
+ try {
+ await this.auth0Client.handleRedirectCallback();
+ this.user = await this.auth0Client.getUser();
+ this.isAuthenticated = true;
+ } catch (e) {
+ this.error = e;
+ } finally {
+ this.loading = false;
+ }
+ },
+ /** Authenticates the user using the redirect method */
+ loginWithRedirect(o) {
+ return this.auth0Client.loginWithRedirect(o);
+ },
+ /** Returns all the claims present in the ID token */
+ getIdTokenClaims(o) {
+ return this.auth0Client.getIdTokenClaims(o);
+ },
+ /** Returns the access token. If the token is invalid or missing, a new one is retrieved */
+ getTokenSilently(o) {
+ return this.auth0Client.getTokenSilently(o);
+ },
+ /** Gets the access token using a popup window */
- getTokenWithPopup(o) {
- return this.auth0Client.getTokenWithPopup(o);
- },
- /** Logs the user out and removes their session on the authorization server */
- logout(o) {
- return this.auth0Client.logout(o);
- }
- },
- /** Use this lifecycle method to instantiate the SDK client */
- async created() {
- // Create a new instance of the SDK client using members of the given options object
- this.auth0Client = await createAuth0Client({
- domain: options.domain,
- client_id: options.clientId,
- audience: options.audience,
- redirect_uri: redirectUri
- });
+ getTokenWithPopup(o) {
+ return this.auth0Client.getTokenWithPopup(o);
+ },
+ /** Logs the user out and removes their session on the authorization server */
+ logout(o) {
+ return this.auth0Client.logout(o);
+ }
+ },
+ /** Use this lifecycle method to instantiate the SDK client */
+ async created() {
+ // Create a new instance of the SDK client using members of the given options object
+ this.auth0Client = await createAuth0Client({
+ domain: options.domain,
+ client_id: options.clientId,
+ audience: options.audience,
+ redirect_uri: redirectUri
+ });
- try {
- // If the user is returning to the app after authentication..
- if (
- window.location.search.includes("code=") &&
- window.location.search.includes("state=")
- ) {
- // handle the redirect and retrieve tokens
- const { appState } = await this.auth0Client.handleRedirectCallback();
+ try {
+ // If the user is returning to the app after authentication..
+ if (
+ window.location.search.includes("code=") &&
+ window.location.search.includes("state=")
+ ) {
+ // handle the redirect and retrieve tokens
+ const { appState } = await this.auth0Client.handleRedirectCallback();
- // Notify subscribers that the redirect callback has happened, passing the appState
- // (useful for retrieving any pre-authentication state)
- onRedirectCallback(appState);
- }
- } catch (e) {
- this.error = e;
- } finally {
- // Initialize our internal authentication state
- this.isAuthenticated = await this.auth0Client.isAuthenticated();
- this.user = await this.auth0Client.getUser();
- this.loading = false;
- }
- }
- });
+ // Notify subscribers that the redirect callback has happened, passing the appState
+ // (useful for retrieving any pre-authentication state)
+ onRedirectCallback(appState);
+ }
+ } catch (e) {
+ this.error = e;
+ } finally {
+ // Initialize our internal authentication state
+ this.isAuthenticated = await this.auth0Client.isAuthenticated();
+ this.user = await this.auth0Client.getUser();
+ this.loading = false;
+ }
+ }
+ });
- return instance;
+ return instance;
};
// Create a simple Vue plugin to expose the wrapper object throughout the application
export const Auth0Plugin = {
- install(Vue, options) {
- Vue.prototype.$auth = useAuth0(options);
- }
+ install(Vue, options) {
+ Vue.prototype.$auth = useAuth0(options);
+ }
};