Added Axios and removed fetch...
Axios has CSXF integrated.
This commit is contained in:
@@ -5,8 +5,9 @@ export class AxiosSuccess {
|
||||
public status: number
|
||||
public data: any
|
||||
|
||||
constructor(data: any) {
|
||||
constructor(data: any, status: number) {
|
||||
this.data = data
|
||||
this.status = status
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +15,12 @@ export class AxiosError {
|
||||
public success: boolean = false
|
||||
public status: number
|
||||
public data: any
|
||||
public code: any
|
||||
|
||||
constructor(status: number, data?: any) {
|
||||
constructor(status: number, data?: any, code?: any) {
|
||||
this.status = status
|
||||
this.data = data
|
||||
this.code = code
|
||||
if (status !== 401) {
|
||||
// if (status == 0) message = 'Vérifiez votre connexion Internet';
|
||||
// NotificationsStore.actions.addNotification({ type: 'warning', message: message })
|
||||
|
||||
@@ -1,50 +1,25 @@
|
||||
import axios, { AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorManager } from 'axios'
|
||||
import Api from '@api'
|
||||
import * as Types from '@src/store/Api/ApiTypes'
|
||||
|
||||
async function sendRequest(url: string, lang: string, mytok: string, method: string, mydata: any) {
|
||||
async function sendRequest(url: string, method: string, mydata: any) {
|
||||
|
||||
console.log('sendRequest', method, url, '[', lang, ']')
|
||||
console.log('sendRequest', method, url)
|
||||
|
||||
const authHeader = new Headers()
|
||||
authHeader.append('content-Type', 'application/json')
|
||||
authHeader.append('Accept', 'application/json')
|
||||
if (url !== process.env.MONGODB_HOST + '/users/login') {
|
||||
authHeader.append('x-auth', mytok)
|
||||
// console.log('TOK PASSATO ALLA FETCH:', mytok)
|
||||
}
|
||||
// authHeader.append('accept-language', lang)
|
||||
|
||||
let configInit: RequestInit
|
||||
|
||||
if (method === 'GET') {
|
||||
configInit = {
|
||||
method: method,
|
||||
cache: 'no-cache',
|
||||
mode: 'cors',
|
||||
headers: authHeader
|
||||
}
|
||||
} else if (method === 'DELETE') {
|
||||
configInit = {
|
||||
method: method,
|
||||
cache: 'no-cache',
|
||||
mode: 'cors',
|
||||
headers: authHeader
|
||||
}
|
||||
} else {
|
||||
configInit = {
|
||||
method: method,
|
||||
cache: 'no-cache',
|
||||
mode: 'cors',
|
||||
headers: authHeader
|
||||
}
|
||||
|
||||
if (mydata !== null)
|
||||
configInit.body = JSON.stringify(mydata)
|
||||
|
||||
}
|
||||
|
||||
const request: Promise<Response> = fetch(url, configInit)
|
||||
return request
|
||||
let request
|
||||
if (method === 'GET')
|
||||
request = Api.get(url, mydata)
|
||||
else if (method === 'POST')
|
||||
request = Api.post(url, mydata)
|
||||
else if (method === 'DELETE')
|
||||
request = Api.Delete(url, mydata)
|
||||
else if (method === 'PUT')
|
||||
request = Api.put(url, mydata)
|
||||
|
||||
const req: Promise<Types.AxiosSuccess | Types.AxiosError> = request
|
||||
return req
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default sendRequest
|
||||
|
||||
@@ -3,8 +3,11 @@ import axios, { AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorMana
|
||||
import router from '@router'
|
||||
import {clone} from 'lodash'
|
||||
import * as Types from './ApiTypes'
|
||||
import { GlobalStore, UserStore } from '@store'
|
||||
import { rescodes } from '@src/store/Modules/rescodes'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
|
||||
export const API_URL = process.env.API_URL
|
||||
export const API_URL = process.env.MONGODB_HOST
|
||||
export const axiosInstance: AxiosInstance = axios.create({
|
||||
baseURL: API_URL,
|
||||
headers: {
|
||||
@@ -32,35 +35,83 @@ export const removeAuthHeaders = () => {
|
||||
delete axiosInstance.defaults.headers.Authorization
|
||||
}
|
||||
|
||||
async function Request(type: string, path: string, payload: any, noAuth?: boolean): Promise<Types.AxiosSuccess | Types.AxiosError> {
|
||||
async function Request(type: string, path: string, payload: any, setAuthToken?: boolean): Promise<Types.AxiosSuccess | Types.AxiosError> {
|
||||
let ricevuto = false
|
||||
try {
|
||||
console.log(`Axios Request [${type}]:`, axiosInstance.defaults)
|
||||
let response: AxiosResponse
|
||||
if (type === 'post' || type === 'put') {
|
||||
response = await axiosInstance[type](path, payload, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
'Content-Type': 'application/json',
|
||||
'x-auth': UserStore.state.x_auth_token
|
||||
}
|
||||
})
|
||||
console.log(new Types.AxiosSuccess(response.data))
|
||||
return new Types.AxiosSuccess(response.data)
|
||||
ricevuto = true
|
||||
// console.log(new Types.AxiosSuccess(response.data, response.status))
|
||||
|
||||
const setAuthToken = (path === '/updatepwd')
|
||||
|
||||
if (response.status === 200) {
|
||||
let x_auth_token = ''
|
||||
try {
|
||||
if (setAuthToken || (path === '/users/login')) {
|
||||
x_auth_token = String(response.headers['x-auth'])
|
||||
|
||||
if (x_auth_token === '') {
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_AUTHENTICATION)
|
||||
}
|
||||
if (setAuthToken) {
|
||||
UserStore.mutations.UpdatePwd(x_auth_token)
|
||||
localStorage.setItem(rescodes.localStorage.token, x_auth_token)
|
||||
}
|
||||
|
||||
UserStore.mutations.setAuth(x_auth_token)
|
||||
localStorage.setItem(rescodes.localStorage.token, x_auth_token)
|
||||
}
|
||||
|
||||
GlobalStore.mutations.setStateConnection(ricevuto ? 'online' : 'offline')
|
||||
UserStore.mutations.setServerCode(rescodes.OK)
|
||||
} catch (e) {
|
||||
if (setAuthToken) {
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_AUTHENTICATION)
|
||||
UserStore.mutations.setAuth('')
|
||||
}
|
||||
GlobalStore.mutations.setStateConnection(ricevuto ? 'online' : 'offline')
|
||||
return Promise.reject(new Types.AxiosError(serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN, null, rescodes.ERR_AUTHENTICATION))
|
||||
}
|
||||
}
|
||||
|
||||
return new Types.AxiosSuccess(response.data, response.status)
|
||||
} else if (type === 'get' || type === 'delete') {
|
||||
// @ts-ignore
|
||||
response = await axiosInstance[type](path, {
|
||||
params: payload,
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
headers: {'Content-Type': 'application/json',
|
||||
'x-auth': UserStore.state.x_auth_token
|
||||
}
|
||||
})
|
||||
return new Types.AxiosSuccess(response.data)
|
||||
return new Types.AxiosSuccess(response.data, response.status)
|
||||
} else if (type === 'postFormData') {
|
||||
response = await axiosInstance.post(path, payload, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
'Content-Type': 'multipart/form-data',
|
||||
'x-auth': UserStore.state.x_auth_token
|
||||
}
|
||||
})
|
||||
return new Types.AxiosSuccess(response.data)
|
||||
return new Types.AxiosSuccess(response.data, response.status)
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROR using', path, error, 'ricevuto=', ricevuto)
|
||||
}
|
||||
if (!ricevuto) {
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_SERVERFETCH)
|
||||
} else {
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
}
|
||||
|
||||
if (error.response) {
|
||||
return Promise.reject(new Types.AxiosError(error.response.status, error.response.data))
|
||||
} else {
|
||||
|
||||
@@ -13,6 +13,7 @@ import { GlobalStore, UserStore } from '@modules'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
import router from '@router'
|
||||
import * as Types from "@src/store/Api/ApiTypes"
|
||||
|
||||
|
||||
// const algoliaApi = new AlgoliaSearch()
|
||||
@@ -47,86 +48,31 @@ export namespace ApiTool {
|
||||
})
|
||||
}
|
||||
|
||||
export async function SendReq(url: string, method: string, mydata: any, setAuthToken: boolean = false) {
|
||||
export async function SendReq(url: string, method: string, mydata: any, setAuthToken: boolean = false): Promise<Types.AxiosSuccess | Types.AxiosError> {
|
||||
UserStore.mutations.setServerCode(rescodes.EMPTY)
|
||||
UserStore.mutations.setResStatus(0)
|
||||
return await new Promise(function (resolve, reject) {
|
||||
let ricevuto = false
|
||||
|
||||
return sendRequest(url, UserStore.state.lang, UserStore.state.x_auth_token, method, mydata)
|
||||
.then(resreceived => {
|
||||
console.log('resreceived', resreceived)
|
||||
ricevuto = true
|
||||
let res = resreceived.clone()
|
||||
if (process.env.DEV) {
|
||||
// console.log('SendReq RES [', res.status, ']', res)
|
||||
}
|
||||
return sendRequest(url, method, mydata)
|
||||
.then(res => {
|
||||
console.log('res', res)
|
||||
|
||||
UserStore.mutations.setResStatus(res.status)
|
||||
if (res.status === 200) {
|
||||
let x_auth_token = ''
|
||||
try {
|
||||
if (setAuthToken) {
|
||||
x_auth_token = String(res.headers.get('x-auth'))
|
||||
|
||||
if (x_auth_token === '') {
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_AUTHENTICATION)
|
||||
}
|
||||
UserStore.mutations.setAuth(x_auth_token)
|
||||
|
||||
if (url === process.env.MONGODB_HOST + '/updatepwd') {
|
||||
UserStore.mutations.UpdatePwd({ x_auth_token })
|
||||
localStorage.setItem(rescodes.localStorage.token, x_auth_token)
|
||||
}
|
||||
}
|
||||
|
||||
UserStore.mutations.setServerCode(rescodes.OK)
|
||||
} catch (e) {
|
||||
if (setAuthToken) {
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_AUTHENTICATION)
|
||||
UserStore.mutations.setAuth('')
|
||||
}
|
||||
GlobalStore.mutations.setStateConnection(ricevuto ? 'online' : 'offline')
|
||||
return reject({ code: rescodes.ERR_AUTHENTICATION })
|
||||
}
|
||||
} else if (res.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
|
||||
if (res.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
|
||||
// Forbidden
|
||||
// You probably is connectiong with other page...
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_AUTHENTICATION)
|
||||
UserStore.mutations.setAuth('')
|
||||
GlobalStore.mutations.setStateConnection(ricevuto ? 'online' : 'offline')
|
||||
router.push('/signin')
|
||||
return reject({ code: rescodes.ERR_AUTHENTICATION })
|
||||
}
|
||||
|
||||
GlobalStore.mutations.setStateConnection(ricevuto ? 'online' : 'offline')
|
||||
|
||||
return res.json()
|
||||
.then((body) => {
|
||||
// console.log('BODY RES = ', body)
|
||||
return resolve({ res, body, status: res.status })
|
||||
})
|
||||
.catch(e => {
|
||||
return resolve({ res, body: {}, status: res.status })
|
||||
// Array not found...
|
||||
// UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
// return reject({ code: rescodes.ERR_GENERICO, status: res.status })
|
||||
})
|
||||
return resolve(res)
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROR using', url, error, 'ricevuto=', ricevuto)
|
||||
}
|
||||
if (!ricevuto) {
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_SERVERFETCH)
|
||||
} else {
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
}
|
||||
|
||||
GlobalStore.mutations.setStateConnection(ricevuto ? 'online' : 'offline')
|
||||
|
||||
return reject({ code: error })
|
||||
console.log('error', error)
|
||||
return reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -200,10 +200,8 @@ namespace Actions {
|
||||
},
|
||||
}
|
||||
|
||||
let call = process.env.MONGODB_HOST + '/subscribe'
|
||||
|
||||
return Api.SendReq(call, 'POST', myres)
|
||||
.then(({ res, body }) => {
|
||||
return Api.SendReq('/subscribe', 'POST', myres)
|
||||
.then(res => {
|
||||
state.wasAlreadySubscribed = true
|
||||
state.wasAlreadySubOnDb = true
|
||||
|
||||
|
||||
@@ -229,30 +229,27 @@ namespace Actions {
|
||||
if (UserStore.state.userId === '')
|
||||
return false // Login not made
|
||||
|
||||
let call = process.env.MONGODB_HOST + '/todos/' + UserStore.state.userId
|
||||
|
||||
state.networkDataReceived = false
|
||||
|
||||
let ris = await Api.SendReq(call, 'GET', null)
|
||||
.then(({ res, body, status }) => {
|
||||
let ris = await Api.SendReq('/todos/' + UserStore.state.userId, 'GET', null)
|
||||
.then(res => {
|
||||
state.networkDataReceived = true
|
||||
|
||||
// console.log('******* UPDATE TODOS.STATE.TODOS !:', res.todos)
|
||||
if (body.todos) {
|
||||
state.todos = [...body.todos]
|
||||
if (res.data.todos) {
|
||||
state.todos = [...res.data.todos]
|
||||
Todos.mutations.setTodos_changed()
|
||||
}
|
||||
|
||||
console.log('********** res', 'state.todos', state.todos, 'checkPending', checkPending)
|
||||
|
||||
// After Login will store into the indexedDb...
|
||||
|
||||
return { status }
|
||||
return res
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('error=', error)
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return { status }
|
||||
return error
|
||||
})
|
||||
|
||||
// console.log('ris : ', ris)
|
||||
@@ -315,7 +312,7 @@ namespace Actions {
|
||||
if (!('serviceWorker' in navigator)) {
|
||||
|
||||
console.log('dbInsertSaveTodo', itemtodo, method)
|
||||
let call = process.env.MONGODB_HOST + '/todos'
|
||||
let call = '/todos'
|
||||
|
||||
if (UserStore.state.userId === '')
|
||||
return false // Login not made
|
||||
@@ -326,8 +323,8 @@ namespace Actions {
|
||||
console.log('TODO TO SAVE: ', itemtodo)
|
||||
|
||||
let res = await Api.SendReq(call, method, itemtodo)
|
||||
.then(({ res, newItem }) => {
|
||||
console.log('dbInsertSaveTodo to the Server', newItem)
|
||||
.then(res => {
|
||||
console.log('dbInsertSaveTodo to the Server', res.data)
|
||||
|
||||
return (res.status === 200)
|
||||
})
|
||||
@@ -345,13 +342,11 @@ namespace Actions {
|
||||
|
||||
if (!('serviceWorker' in navigator)) {
|
||||
// console.log('dbDeleteTodo', item)
|
||||
let call = process.env.MONGODB_HOST + '/todos/' + item._id
|
||||
|
||||
if (UserStore.state.userId === '')
|
||||
return false // Login not made
|
||||
|
||||
let res = await Api.SendReq(call, 'DELETE', item)
|
||||
.then(function ({ res, itemris }) {
|
||||
let res = await Api.SendReq('/todos/' + item._id, 'DELETE', item)
|
||||
.then(res => {
|
||||
console.log('dbDeleteTodo to the Server')
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
@@ -107,12 +107,12 @@ namespace Mutations {
|
||||
localStorage.setItem(rescodes.localStorage.lang, state.lang)
|
||||
}
|
||||
|
||||
function UpdatePwd(state: IUserState, data: IIdToken) {
|
||||
state.x_auth_token = data.x_auth_token
|
||||
function UpdatePwd(state: IUserState, x_auth_token: string) {
|
||||
state.x_auth_token = x_auth_token
|
||||
if (!state.tokens) {
|
||||
state.tokens = []
|
||||
}
|
||||
state.tokens.push({ access: 'auth', token: data.x_auth_token, data_login: new Date() })
|
||||
state.tokens.push({ access: 'auth', token: x_auth_token, data_login: new Date() })
|
||||
}
|
||||
|
||||
function setServerCode(state: IUserState, num: number) {
|
||||
@@ -208,8 +208,6 @@ namespace Actions {
|
||||
}
|
||||
|
||||
async function resetpwd(context, paramquery: IUserState) {
|
||||
let call = process.env.MONGODB_HOST + '/updatepwd'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
@@ -222,9 +220,9 @@ namespace Actions {
|
||||
|
||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||
|
||||
return await Api.SendReq(call, 'POST', usertosend, true)
|
||||
.then(({ res, body }) => {
|
||||
return { code: body.code, msg: body.msg }
|
||||
return await Api.SendReq('/updatepwd', 'POST', usertosend, true)
|
||||
.then(res => {
|
||||
return { code: res.data.code, msg: res.data.msg }
|
||||
})
|
||||
.catch((error) => {
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
@@ -235,9 +233,6 @@ namespace Actions {
|
||||
|
||||
async function requestpwd(context, paramquery: IUserState) {
|
||||
|
||||
let call = process.env.MONGODB_HOST + '/requestnewpwd'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
idapp: process.env.APP_ID,
|
||||
@@ -247,9 +242,9 @@ namespace Actions {
|
||||
|
||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||
|
||||
return await Api.SendReq(call, 'POST', usertosend)
|
||||
.then(({ res, body }) => {
|
||||
return { code: body.code, msg: body.msg }
|
||||
return await Api.SendReq('/requestnewpwd', 'POST', usertosend)
|
||||
.then(res => {
|
||||
return { code: res.data.code, msg: res.data.msg }
|
||||
}).catch((error) => {
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return UserStore.getters.getServerCode
|
||||
@@ -258,9 +253,6 @@ namespace Actions {
|
||||
}
|
||||
|
||||
async function vreg(context, paramquery: ILinkReg) {
|
||||
let call = process.env.MONGODB_HOST + '/vreg'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
idapp: process.env.APP_ID,
|
||||
@@ -270,17 +262,17 @@ namespace Actions {
|
||||
|
||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||
|
||||
return await Api.SendReq(call, 'POST', usertosend)
|
||||
.then(({ res, body }) => {
|
||||
return await Api.SendReq('/vreg', 'POST', usertosend)
|
||||
.then(res => {
|
||||
// console.log("RITORNO 2 ");
|
||||
// mutations.setServerCode(myres);
|
||||
if (body.code === serv_constants.RIS_CODE_EMAIL_VERIFIED) {
|
||||
if (res.data.code === serv_constants.RIS_CODE_EMAIL_VERIFIED) {
|
||||
console.log('VERIFICATO !!')
|
||||
localStorage.setItem(rescodes.localStorage.verified_email, String(true))
|
||||
} else {
|
||||
console.log('Risultato di vreg: ', body.code)
|
||||
console.log('Risultato di vreg: ', res.data.code)
|
||||
}
|
||||
return { code: body.code, msg: body.msg }
|
||||
return { code: res.data.code, msg: res.data.msg }
|
||||
}).catch((error) => {
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return UserStore.getters.getServerCode
|
||||
@@ -288,8 +280,7 @@ namespace Actions {
|
||||
}
|
||||
|
||||
async function signup(context, authData: ISignupOptions) {
|
||||
let call = process.env.MONGODB_HOST + '/users'
|
||||
console.log('CALL ' + call)
|
||||
console.log('SIGNUP')
|
||||
|
||||
// console.log("PASSW: " + authData.password);
|
||||
|
||||
@@ -309,21 +300,18 @@ namespace Actions {
|
||||
|
||||
console.log(usertosend)
|
||||
|
||||
let myres: IResult
|
||||
|
||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||
|
||||
return Api.SendReq(call, 'POST', usertosend)
|
||||
.then(({ res, body }) => {
|
||||
myres = res
|
||||
return Api.SendReq('/users', 'POST', usertosend)
|
||||
.then(res => {
|
||||
|
||||
const newuser = body
|
||||
const newuser = res.data
|
||||
|
||||
console.log('newuser', newuser)
|
||||
|
||||
Mutations.mutations.setServerCode(myres.status)
|
||||
Mutations.mutations.setServerCode(res.status)
|
||||
|
||||
if (myres.status === 200) {
|
||||
if (res.status === 200) {
|
||||
let userId = newuser._id
|
||||
let username = authData.username
|
||||
if (process.env.DEV) {
|
||||
@@ -363,22 +351,25 @@ namespace Actions {
|
||||
}
|
||||
|
||||
async function signin(context, authData: ISigninOptions) {
|
||||
let call = process.env.MONGODB_HOST + '/users/login'
|
||||
console.log('LOGIN ' + call)
|
||||
console.log('LOGIN ')
|
||||
|
||||
console.log('MYLANG = ' + state.lang)
|
||||
|
||||
let sub = null
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
sub = await navigator.serviceWorker.ready
|
||||
.then(function (swreg) {
|
||||
let sub = swreg.pushManager.getSubscription()
|
||||
return sub
|
||||
})
|
||||
.catch(e => {
|
||||
sub = null
|
||||
})
|
||||
try {
|
||||
if ('serviceWorker' in navigator) {
|
||||
sub = await navigator.serviceWorker.ready
|
||||
.then(function (swreg) {
|
||||
let sub = swreg.pushManager.getSubscription()
|
||||
return sub
|
||||
})
|
||||
.catch(e => {
|
||||
sub = null
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Err navigator.serviceWorker.ready ... GetSubscription:', e)
|
||||
}
|
||||
|
||||
const options = {
|
||||
@@ -403,48 +394,29 @@ namespace Actions {
|
||||
|
||||
let myres: any
|
||||
|
||||
return Api.SendReq(call, 'POST', usertosend, true)
|
||||
.then(({ res, body }) => {
|
||||
return Api.SendReq('/users/login', 'POST', usertosend, true)
|
||||
.then(res => {
|
||||
myres = res
|
||||
|
||||
if (body.code === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
Mutations.mutations.setServerCode(body.code)
|
||||
return { myres, body }
|
||||
if (myres.data.code === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
Mutations.mutations.setServerCode(myres.data.code)
|
||||
return myres
|
||||
}
|
||||
|
||||
Mutations.mutations.setServerCode(myres.status)
|
||||
|
||||
if (myres.status !== 200) {
|
||||
return Promise.reject(rescodes.ERR_GENERICO)
|
||||
}
|
||||
return { myres, body }
|
||||
return myres
|
||||
|
||||
}).then(({ myres, body }) => {
|
||||
}).then(res => {
|
||||
|
||||
if (myres.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code)
|
||||
}
|
||||
return body.code
|
||||
} else if (myres.status !== 200) {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code)
|
||||
}
|
||||
return body.code
|
||||
}
|
||||
if (res.success) {
|
||||
GlobalStore.mutations.SetwasAlreadySubOnDb(res.data.subsExistonDb)
|
||||
|
||||
if (myres.status === 200) {
|
||||
GlobalStore.mutations.SetwasAlreadySubOnDb(body.subsExistonDb)
|
||||
|
||||
let myuser: IUserState = body.usertosend
|
||||
let myuser: IUserState = res.data.usertosend
|
||||
if (myuser) {
|
||||
let userId = myuser.userId
|
||||
let username = authData.username
|
||||
let verified_email = myuser.verified_email
|
||||
if (process.env.DEV) {
|
||||
console.log('USERNAME = ' + username, 'IDUSER= ' + userId)
|
||||
// console.log('state.x_auth_token= ' + state.x_auth_token)
|
||||
}
|
||||
|
||||
Mutations.mutations.authUser({
|
||||
userId,
|
||||
@@ -501,17 +473,14 @@ namespace Actions {
|
||||
|
||||
await GlobalStore.actions.clearDataAfterLogout()
|
||||
|
||||
let call = process.env.MONGODB_HOST + '/users/me/token'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
idapp: process.env.APP_ID
|
||||
}
|
||||
|
||||
console.log(usertosend)
|
||||
const riscall = await Api.SendReq(call, 'DELETE', usertosend)
|
||||
.then(({ res, body }) => {
|
||||
const riscall = await Api.SendReq('/users/me/token', 'DELETE', usertosend)
|
||||
.then(res => {
|
||||
console.log(res)
|
||||
}).then(() => {
|
||||
Mutations.mutations.clearAuthData()
|
||||
|
||||
@@ -68,7 +68,7 @@ export const rescodes = {
|
||||
value: 0,
|
||||
icon: 'expand_more'
|
||||
}],
|
||||
'es': [
|
||||
'esEs': [
|
||||
{
|
||||
id: 1,
|
||||
label: 'Alta',
|
||||
@@ -169,7 +169,7 @@ export const rescodes = {
|
||||
checked: false
|
||||
}
|
||||
],
|
||||
'es': [
|
||||
'esEs': [
|
||||
{
|
||||
id: 10,
|
||||
label: '',
|
||||
|
||||
Reference in New Issue
Block a user