feat: improve OIDC login flow and stores handling
Some checks failed
TrafficCue CI / check (push) Failing after 1m58s
TrafficCue CI / build-android (push) Has been cancelled
TrafficCue CI / build (push) Has started running

This commit is contained in:
2025-09-29 18:54:12 +02:00
parent 004ba9047f
commit f5e1e23cdd
6 changed files with 89 additions and 39 deletions

35
src/OIDCCallback.svelte Normal file
View File

@ -0,0 +1,35 @@
<script>
import { uploadID } from "$lib/services/lnv";
import { getOIDCUser } from "$lib/services/oidc";
import { onMount } from "svelte";
const url = new URL(location.href);
const code = url.searchParams.get("code");
const state = url.searchParams.get("state");
const storedState = localStorage.getItem("lnv-oidcstate");
const codeVerifier = localStorage.getItem("lnv-codeVerifier");
localStorage.removeItem("lnv-oidcstate");
localStorage.removeItem("lnv-codeVerifier");
async function login() {
if (!code || !state || !codeVerifier || !storedState) {
alert("Missing code, state, codeVerifier or storedState.");
return;
}
if (state !== storedState) {
alert("State mismatch. Please try again.");
return;
}
const token = await getOIDCUser(code, codeVerifier);
localStorage.setItem("lnv-id", token.id_token);
localStorage.setItem("lnv-token", token.access_token);
localStorage.setItem("lnv-refresh", token.refresh_token);
await uploadID();
}
onMount(async () => {
await login();
location.href = "/";
})
</script>