From dc258852cebcfd85446deebf31347b9ce7c3eef4 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 7 Nov 2018 18:50:51 +0000 Subject: [PATCH] --- app/ayanova/src/api/auth.js | 61 ++++++++++++++++----------------- app/ayanova/src/utils/auth.js | 12 +++++-- app/ayanova/src/utils/config.js | 3 +- 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/app/ayanova/src/api/auth.js b/app/ayanova/src/api/auth.js index 2ef5ccc5..e53cdae2 100644 --- a/app/ayanova/src/api/auth.js +++ b/app/ayanova/src/api/auth.js @@ -1,40 +1,37 @@ -/*eslint-disable*/ import config from "../utils/config"; import api from "./apiutil"; - -// function status(response) { -// if (response.status >= 200 && response.status < 300) { -// return Promise.resolve(response); -// } else { -// return Promise.reject(new Error(response.statusText)); -// } -// } - -// function json(response) { -// return response.json(); -// } +import { processLogin, processLogout } from "../utils/auth"; export default { async authenticate(login, password) { - return fetch(config.apiUrl + "auth", { - method: "post", - mode: "cors", - headers: { - Accept: "application/json, text/plain, */*", - "Content-Type": "application/json" - }, - body: JSON.stringify({ - login: login, - password: password + return ( + fetch(config.apiUrl + "auth", { + method: "post", + mode: "cors", + headers: { + Accept: "application/json, text/plain, */*", + "Content-Type": "application/json" + }, + body: JSON.stringify({ + login: login, + password: password + }) }) - }) - .then(api.status) - .then(api.json) - .then(function(data) { - return data; - }) - .catch(function(error) { - return Promise.reject(error); - }); + .then(api.status) + .then(api.json) + .then(processLogin) + .then(() => { + return Promise.resolve(true); + }) //succeeded, nothing to return + // .then(function(data) { + // //todo: this should just return a bool on successful login and let the util\auth handle storing token etc + // //router will handle views available based on roles etc so login only really needs to know if it succeeded or not. + // return data; + // }) + .catch(function(error) { + processLogout(); + return Promise.reject(error); + }) + ); } }; diff --git a/app/ayanova/src/utils/auth.js b/app/ayanova/src/utils/auth.js index fa27868f..6ad8ddad 100644 --- a/app/ayanova/src/utils/auth.js +++ b/app/ayanova/src/utils/auth.js @@ -1,3 +1,5 @@ +/* eslint-disable */ + import decode from "jwt-decode"; //import axios from 'axios'; //import auth0 from 'auth0-js'; @@ -55,7 +57,12 @@ const USER_ROLES = AuthorizationRoles.NoRole; // domain: CLIENT_DOMAIN // }); -export function login() { +export function processLogin(response) { + if (response) { + debugger; + } + + return Promise.resolve(true); // auth.authorize({ // responseType: 'token id_token', // redirectUri: REDIRECT, @@ -68,7 +75,8 @@ export function login() { // mode: 'history', // }); -export function logout() { +export function processLogout() { + console.log("util\\auth.js->ProcessLogout called!"); clearIdToken(); clearAccessToken(); //router.go('/'); diff --git a/app/ayanova/src/utils/config.js b/app/ayanova/src/utils/config.js index ba547eeb..3574d298 100644 --- a/app/ayanova/src/utils/config.js +++ b/app/ayanova/src/utils/config.js @@ -1,4 +1,5 @@ export default { apiUrl: "http://localhost:7575/api/v8.0/", - apiToken: "" + apiToken: "", + roles: 0 };