Skip to content

Commit

Permalink
Migrate locator-tool to Vue
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 committed Feb 4, 2024
1 parent 56b2c1f commit dd503ad
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions app/api/ltDataAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@ interface EditApiResponse {
}

export function getUserInfo() {
return useFetch<UserApiResponse>('/user');
return useFetch<UserApiResponse>('/user', {
headers: {
'X-XSRF-TOKEN': xsrfToken() || ''
}
});
}

export function editLocation(title: CommonsFile, coordinates: LatLng) {
const {pageid} = title;
const {type, lat, lng} = coordinates;
const xsrfToken = document.cookie
.split(';')
.find(item => item.trim().startsWith('XSRF-TOKEN='))
?.trim()
?.slice('XSRF-TOKEN='.length);
return useFetch<EditApiResponse>(
'/edit',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-XSRF-TOKEN': xsrfToken || ''
'X-XSRF-TOKEN': xsrfToken() || ''
},
body: JSON.stringify({type, lat, lng, pageid})
},
Expand All @@ -47,6 +46,14 @@ export function editLocation(title: CommonsFile, coordinates: LatLng) {
);
}

function xsrfToken() {
return document.cookie
.split(';')
.find(item => item.trim().startsWith('XSRF-TOKEN='))
?.trim()
?.slice('XSRF-TOKEN='.length);
}

export function loginURL(): string {
return '/login?next=' + encodeURIComponent('/' + location.hash);
}
Expand Down

0 comments on commit dd503ad

Please sign in to comment.