Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 弱掃問題修正 #372

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Taipei-City-Dashboard-FE/src/router/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
// This file centrally handles all axios requests made in the application.

import axios from "axios";
import { usePersonStore } from "../store/personStore";
import { usePersonStore } from "../store/personStore.js";
import { useDialogStore } from "../store/dialogStore";
import { useContentStore } from "../store/contentStore";
import { DataManager } from "../assets/utilityFunctions/dataManager.js";

const http = axios.create({
baseURL: import.meta.env.VITE_API_URL,
Expand All @@ -23,8 +24,8 @@ http.interceptors.request.use((request) => {
contentStore.loading = true;
contentStore.error = false;

if (personStore.token) {
request.headers.setAuthorization(`Bearer ${personStore.token}`);
if (personStore.code) {
request.headers.setAuthorization(`Bearer ${personStore.code}`);
} else {
request.headers.setAuthorization(`Bearer`);
}
Expand All @@ -36,9 +37,11 @@ http.interceptors.response.use(
(response) => {
// handle loading directly in request since sometimes requests are stringed together
const personStore = usePersonStore();
if (response.data.token) {
personStore.token = response.data.token;
localStorage.setItem("token", response.data.token);
const dataManager = new DataManager(response.data);

if (dataManager.getData("data")) {
personStore.code = dataManager.getData("data");
localStorage.setItem("code", personStore.code);
}
return response;
},
Expand All @@ -52,7 +55,7 @@ http.interceptors.response.use(

switch (error.response.status) {
case 401:
if (personStore.token) {
if (personStore.code) {
dialogStore.showNotification(
"fail",
"401,登入逾時,請重新登入"
Expand All @@ -66,7 +69,7 @@ http.interceptors.response.use(
}
break;
case 403:
if (personStore.token) {
if (personStore.code) {
dialogStore.showNotification(
"fail",
"403,沒有權限執行此動作"
Expand Down
14 changes: 12 additions & 2 deletions Taipei-City-Dashboard-FE/src/store/mapStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ export const useMapStore = defineStore("map", {
const personStore = usePersonStore();
if (!this.map) return;
// Taipei District Labels
fetch(`/mapData/taipei_town.geojson`)
fetch(`/mapData/taipei_town.geojson`, {
method: 'GET',
headers: {
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
}
})
.then((response) => response.json())
.then((data) => {
this.map
Expand All @@ -141,7 +146,12 @@ export const useMapStore = defineStore("map", {
.addLayer(TaipeiTown);
});
// Taipei Village Labels
fetch(`/mapData/taipei_village.geojson`)
fetch(`/mapData/taipei_village.geojson`, {
method: 'GET',
headers: {
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
}
})
.then((response) => response.json())
.then((data) => {
this.map
Expand Down
Loading