parent
42b2390bd7
commit
82dd786210
@ -1,6 +1,9 @@
|
||||
<script>
|
||||
import { apikey, lang } from "./store.js";
|
||||
import { apikey, lang,stationinfo } from "./store.js";
|
||||
import axios from 'axios';
|
||||
let token;
|
||||
$: error=false;
|
||||
$: errormessage="";
|
||||
$: isTokenValid =
|
||||
token?.length === 44 &&
|
||||
token.split(".")[0].length === 7 &&
|
||||
@ -43,9 +46,21 @@
|
||||
class="flex flex-col pt-3 md:pt-8"
|
||||
onsubmit="event.preventDefault();"
|
||||
on:submit={() => {
|
||||
// TODO: validate token with backend api
|
||||
console.log(token);
|
||||
axios.request({
|
||||
method: 'GET',
|
||||
url: 'https://dev.lauf-fuer-kaya.de/api/stations/me',
|
||||
headers: {Authorization: 'Bearer '+token}
|
||||
}).then(function (response) {
|
||||
console.log(response.data);
|
||||
error=false;
|
||||
errormessage="";
|
||||
apikey.set(token);
|
||||
stationinfo.set(JSON.stringify(response.data));
|
||||
}).catch(function (e) {
|
||||
console.log(e.response.data.short);
|
||||
error=true;
|
||||
errormessage=e.response.data.short;
|
||||
});
|
||||
}}
|
||||
>
|
||||
<div class="flex flex-col pt-4">
|
||||
|
@ -5,6 +5,11 @@ export const apikey = writable(stored_apikey);
|
||||
apikey.subscribe((value) => {
|
||||
localStorage.setItem('apikey', value);
|
||||
});
|
||||
const stored_stationinfo = localStorage.getItem('stationinfo');
|
||||
export const stationinfo = writable(stored_stationinfo);
|
||||
stationinfo.subscribe((value) => {
|
||||
localStorage.setItem('stationinfo', value);
|
||||
});
|
||||
const stored_page = localStorage.getItem('page');
|
||||
export const page = writable(stored_page);
|
||||
page.subscribe((value) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user