This commit is contained in:
@@ -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);
|
||||
})
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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('/');
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export default {
|
||||
apiUrl: "http://localhost:7575/api/v8.0/",
|
||||
apiToken: ""
|
||||
apiToken: "",
|
||||
roles: 0
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user