feat: upload ID to server
Some checks failed
TrafficCue CI / check (push) Failing after 32s
TrafficCue CI / build (push) Failing after 38s

This commit is contained in:
Cfp
2025-08-21 14:24:35 +02:00
parent 2f6f17ca52
commit 15e88979d5
2 changed files with 18 additions and 1 deletions

View File

@ -5,7 +5,7 @@
import { getAuthURL, getOIDCUser } from "$lib/services/oidc";
import * as Avatar from "$lib/components/ui/avatar";
import { m } from "$lang/messages";
import { refreshToken } from "$lib/services/lnv";
import { refreshToken, uploadID } from "$lib/services/lnv";
interface OIDCUser {
sub: string;
@ -58,6 +58,7 @@
user = JSON.parse(
atob((localStorage.getItem("lnv-id") || "").split(".")[1]),
);
await uploadID();
});
}}>{m["sidebar.user.login"]()}</Button
>

View File

@ -53,6 +53,21 @@ export async function hasCapability(
return caps.includes(capability);
}
export async function uploadID() {
const res = await fetch(LNV_SERVER + "/user", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
token: localStorage.getItem("lnv-id")
})
});
if(!res.ok) {
alert("Failed to upload user data.");
}
}
export async function refreshToken() {
const config = await getOIDCConfig();
if(!config) throw new Error("Server does not support OIDC.");
@ -78,6 +93,7 @@ export async function refreshToken() {
localStorage.setItem("lnv-id", data.id_token);
localStorage.setItem("lnv-token", data.access_token);
localStorage.setItem("lnv-refresh", data.refresh_token);
await uploadID();
}
export async function authFetch(url: string, params?: RequestInit): ReturnType<typeof fetch> {