This commit is contained in:
2018-11-07 18:50:51 +00:00
parent d21f40213a
commit dc258852ce
3 changed files with 41 additions and 35 deletions

View File

@@ -1,22 +1,11 @@
/*eslint-disable*/
import config from "../utils/config"; import config from "../utils/config";
import api from "./apiutil"; import api from "./apiutil";
import { processLogin, processLogout } from "../utils/auth";
// 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();
// }
export default { export default {
async authenticate(login, password) { async authenticate(login, password) {
return fetch(config.apiUrl + "auth", { return (
fetch(config.apiUrl + "auth", {
method: "post", method: "post",
mode: "cors", mode: "cors",
headers: { headers: {
@@ -30,11 +19,19 @@ export default {
}) })
.then(api.status) .then(api.status)
.then(api.json) .then(api.json)
.then(function(data) { .then(processLogin)
return data; .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) { .catch(function(error) {
processLogout();
return Promise.reject(error); return Promise.reject(error);
}); })
);
} }
}; };

View File

@@ -1,3 +1,5 @@
/* eslint-disable */
import decode from "jwt-decode"; import decode from "jwt-decode";
//import axios from 'axios'; //import axios from 'axios';
//import auth0 from 'auth0-js'; //import auth0 from 'auth0-js';
@@ -55,7 +57,12 @@ const USER_ROLES = AuthorizationRoles.NoRole;
// domain: CLIENT_DOMAIN // domain: CLIENT_DOMAIN
// }); // });
export function login() { export function processLogin(response) {
if (response) {
debugger;
}
return Promise.resolve(true);
// auth.authorize({ // auth.authorize({
// responseType: 'token id_token', // responseType: 'token id_token',
// redirectUri: REDIRECT, // redirectUri: REDIRECT,
@@ -68,7 +75,8 @@ export function login() {
// mode: 'history', // mode: 'history',
// }); // });
export function logout() { export function processLogout() {
console.log("util\\auth.js->ProcessLogout called!");
clearIdToken(); clearIdToken();
clearAccessToken(); clearAccessToken();
//router.go('/'); //router.go('/');

View File

@@ -1,4 +1,5 @@
export default { export default {
apiUrl: "http://localhost:7575/api/v8.0/", apiUrl: "http://localhost:7575/api/v8.0/",
apiToken: "" apiToken: "",
roles: 0
}; };