mirror of
https://github.com/1f349/admin.1f349.com.git
synced 2025-02-22 21:44:57 +00:00
Verify token on startup
This commit is contained in:
parent
a10ed84d6a
commit
76b24f3f68
@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {SvelteComponent} from "svelte";
|
import {onMount, type SvelteComponent} from "svelte";
|
||||||
import GeneralView from "./views/GeneralView.svelte";
|
import GeneralView from "./views/GeneralView.svelte";
|
||||||
import RoutesView from "./views/RoutesView.svelte";
|
import RoutesView from "./views/RoutesView.svelte";
|
||||||
import RedirectsView from "./views/RedirectsView.svelte";
|
import RedirectsView from "./views/RedirectsView.svelte";
|
||||||
@ -8,6 +8,7 @@
|
|||||||
import {loginStore, parseJwt, type LoginStore} from "./stores/login";
|
import {loginStore, parseJwt, type LoginStore} from "./stores/login";
|
||||||
import {openLoginPopup} from "./utils/login-popup";
|
import {openLoginPopup} from "./utils/login-popup";
|
||||||
import {domainOption} from "./stores/domain-option";
|
import {domainOption} from "./stores/domain-option";
|
||||||
|
import {apiVerify} from "./utils/api-request";
|
||||||
|
|
||||||
let sidebarOptions: Array<{name: string; view: typeof SvelteComponent<{}>}> = [
|
let sidebarOptions: Array<{name: string; view: typeof SvelteComponent<{}>}> = [
|
||||||
{name: "General", view: GeneralView},
|
{name: "General", view: GeneralView},
|
||||||
@ -31,6 +32,10 @@
|
|||||||
if (!jwt) return [];
|
if (!jwt) return [];
|
||||||
return jwt.per.filter((x: string) => x.startsWith("domain:owns=")).map((x: string) => x.slice("domain:owns=".length));
|
return jwt.per.filter((x: string) => x.startsWith("domain:owns=")).map((x: string) => x.slice("domain:owns=".length));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
apiVerify().catch(() => {});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
@ -103,7 +108,9 @@
|
|||||||
height: 70px;
|
height: 70px;
|
||||||
padding: 0 32px;
|
padding: 0 32px;
|
||||||
background-color: #2c2c2c;
|
background-color: #2c2c2c;
|
||||||
box-shadow: 0 4px 8px #0003, 0 6px 20px #00000030;
|
box-shadow:
|
||||||
|
0 4px 8px #0003,
|
||||||
|
0 6px 20px #00000030;
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -198,7 +205,9 @@
|
|||||||
footer {
|
footer {
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
background-color: #2c2c2c;
|
background-color: #2c2c2c;
|
||||||
box-shadow: 0 -4px 8px #0003, 0 -6px 20px #00000030;
|
box-shadow:
|
||||||
|
0 -4px 8px #0003,
|
||||||
|
0 -6px 20px #00000030;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {Writable} from "svelte/store";
|
import type {Writable} from "svelte/store";
|
||||||
import {type CSPair, noCPair, noSPair, noPair, yesCPair} from "../types/cspair";
|
import {type CSPair, noCPair, noSPair, yesCPair} from "../types/cspair";
|
||||||
import {redirectKeys, redirectEqual, type Redirect} from "../types/target";
|
import {redirectKeys, redirectEqual, type Redirect} from "../types/target";
|
||||||
import Flags from "./Flags.svelte";
|
import Flags from "./Flags.svelte";
|
||||||
import RedirectCode from "./RedirectCode.svelte";
|
import RedirectCode from "./RedirectCode.svelte";
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import {get} from "svelte/store";
|
import {get} from "svelte/store";
|
||||||
import {getBearer, loginStore} from "../stores/login";
|
import {getBearer, loginStore} from "../stores/login";
|
||||||
|
|
||||||
|
const TOKEN_VERIFY_API = import.meta.env.VITE_SSO_ORIGIN + "/refresh";
|
||||||
const TOKEN_REFRESH_API = import.meta.env.VITE_SSO_ORIGIN + "/refresh";
|
const TOKEN_REFRESH_API = import.meta.env.VITE_SSO_ORIGIN + "/refresh";
|
||||||
|
|
||||||
export async function apiRequest(url: string, init?: RequestInit): Promise<Response> {
|
export async function apiRequest(url: string, init?: RequestInit): Promise<Response> {
|
||||||
@ -33,3 +34,7 @@ export async function apiRequest(url: string, init?: RequestInit): Promise<Respo
|
|||||||
init.headers = {...init.headers, Authorization: getBearer()};
|
init.headers = {...init.headers, Authorization: getBearer()};
|
||||||
return await fetch(url, init);
|
return await fetch(url, init);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function apiVerify() {
|
||||||
|
return await apiRequest(TOKEN_VERIFY_API);
|
||||||
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {domainOption} from "../stores/domain-option";
|
import {domainOption} from "../stores/domain-option";
|
||||||
import {getBearer} from "../stores/login";
|
|
||||||
import {type Cert, certsTable} from "../stores/certs";
|
import {type Cert, certsTable} from "../stores/certs";
|
||||||
import {apiRequest} from "../utils/api-request";
|
import {apiRequest} from "../utils/api-request";
|
||||||
import {onMount} from "svelte";
|
|
||||||
|
|
||||||
const apiOrchid = import.meta.env.VITE_API_ORCHID;
|
const apiOrchid = import.meta.env.VITE_API_ORCHID;
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {domainOption} from "../stores/domain-option";
|
import {domainOption} from "../stores/domain-option";
|
||||||
import {getBearer} from "../stores/login";
|
|
||||||
import {type Site, sitesTable} from "../stores/sites";
|
import {type Site, sitesTable} from "../stores/sites";
|
||||||
import {apiRequest} from "../utils/api-request";
|
import {apiRequest} from "../utils/api-request";
|
||||||
|
|
||||||
|
@ -6,10 +6,7 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {apiRequest} from "../utils/api-request";
|
import {apiRequest} from "../utils/api-request";
|
||||||
|
|
||||||
import {writable, type Writable} from "svelte/store";
|
import {writable, type Writable} from "svelte/store";
|
||||||
|
|
||||||
import {getBearer} from "../stores/login";
|
|
||||||
import type {CSPair} from "../types/cspair";
|
import type {CSPair} from "../types/cspair";
|
||||||
import {domainOption} from "../stores/domain-option";
|
import {domainOption} from "../stores/domain-option";
|
||||||
import {type CountStats, tableCountStats} from "../stores/target";
|
import {type CountStats, tableCountStats} from "../stores/target";
|
||||||
@ -77,9 +74,8 @@
|
|||||||
})
|
})
|
||||||
.sort((a, _) => (a.type === "del" ? -1 : a.type === "ins" ? 1 : 0))
|
.sort((a, _) => (a.type === "del" ? -1 : a.type === "ins" ? 1 : 0))
|
||||||
.map(x => {
|
.map(x => {
|
||||||
x.v.p = fetch(apiUrl, {
|
x.v.p = apiRequest(apiUrl, {
|
||||||
method: x.type == "del" ? "DELETE" : "POST",
|
method: x.type == "del" ? "DELETE" : "POST",
|
||||||
headers: {Authorization: getBearer()},
|
|
||||||
body: JSON.stringify(x.type == "del" ? {src: (x.v.server as T).src} : x.v.client),
|
body: JSON.stringify(x.type == "del" ? {src: (x.v.server as T).src} : x.v.client),
|
||||||
}).then(x => {
|
}).then(x => {
|
||||||
if (x.status !== 200) throw new Error("Unexpected status code: " + x.status);
|
if (x.status !== 200) throw new Error("Unexpected status code: " + x.status);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user