Skip to content

Commit

Permalink
RED-49 fix invalid token bug.... for the moment
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed Jan 4, 2024
1 parent 4096d79 commit 1d07188
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const filtro = reactive({
limit: 1000
})
const movimentacoes = computed(() => movimentacaoStore.store?.movimentacoes.map((m) => m) || [])
const movimentacoes = computed(() => movimentacaoStore.store?.movimentacoes || [])
const saldo = computed(() => movimentacaoStore.saldo())
Expand Down
7 changes: 3 additions & 4 deletions web-app-vue/src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ const uriParams = ({ uri, params }) =>
.join('&')}`

const req = async ({ method = 'POST', uri, payload }) => {
const token = useUserStore().store.token
const { router } = await import('./router')
const userStore = useUserStore()
const url = `${import.meta.env.VITE_API_URL}${uri}`
const headers = {
'Content-Type': 'application/json',
Accept: 'application/json'
}
if (token) headers['Authorization'] = `Bearer ${token}`
if (userStore.store.token) headers['Authorization'] = `Bearer ${userStore.store.token}`
try {
const result = await fetch(url, {
body: JSON.stringify(payload),
Expand All @@ -29,7 +28,7 @@ const req = async ({ method = 'POST', uri, payload }) => {
}
} catch (e) {
if(e.status === 401) {
router.push('/auth')
await userStore.logout()
}
throw new Error(`${e.status} - ${await e.text()}`)
}
Expand Down
5 changes: 3 additions & 2 deletions web-app-vue/src/stores/movimentacaoStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const useMovimentacaoStore = defineStore('movimentacao-store', () => {
setRedLine({ ...redLine, ...store })
}

const getMovimentacao = id => store.movimentacoes?.find(m => m.id == id)
const getMovimentacao = (id) => store.movimentacoes?.find((m) => m.id == id)

const calcula = (m) => {
const v = parseFloat(m.valor)
Expand All @@ -74,7 +74,8 @@ export const useMovimentacaoStore = defineStore('movimentacao-store', () => {
}

const saldo = () => {
return store.movimentacoes.reduce(
if (!store.movimentacoes || !store.movimentacoes.length) return 0
return store.movimentacoes?.reduce(
(p, c) => {
return { valor: calcula(p) + calcula(c), tipo_movimentacao_id: 1 }
},
Expand Down
4 changes: 3 additions & 1 deletion web-app-vue/src/stores/userStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export const useUserStore = defineStore("user-store", () => {

const doLogin = ({email, senha}) => login({email, senha})

const logout = () => {
const logout = async () => {
const { router } = await import('../services/router')
store.token = null;
clearRedLine();
router.push('/auth')
};

const deleteAccount = async ({ email, senha }) => {
Expand Down

0 comments on commit 1d07188

Please sign in to comment.