feat: upload ID to server
This commit is contained in:
@ -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
|
||||
>
|
||||
|
||||
@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user