This commit is contained in:
@@ -1,40 +1,37 @@
|
|||||||
/*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 (
|
||||||
method: "post",
|
fetch(config.apiUrl + "auth", {
|
||||||
mode: "cors",
|
method: "post",
|
||||||
headers: {
|
mode: "cors",
|
||||||
Accept: "application/json, text/plain, */*",
|
headers: {
|
||||||
"Content-Type": "application/json"
|
Accept: "application/json, text/plain, */*",
|
||||||
},
|
"Content-Type": "application/json"
|
||||||
body: JSON.stringify({
|
},
|
||||||
login: login,
|
body: JSON.stringify({
|
||||||
password: password
|
login: login,
|
||||||
|
password: password
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
.then(api.status)
|
||||||
.then(api.status)
|
.then(api.json)
|
||||||
.then(api.json)
|
.then(processLogin)
|
||||||
.then(function(data) {
|
.then(() => {
|
||||||
return data;
|
return Promise.resolve(true);
|
||||||
})
|
}) //succeeded, nothing to return
|
||||||
.catch(function(error) {
|
// .then(function(data) {
|
||||||
return Promise.reject(error);
|
// //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);
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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('/');
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user