♻️ Brand new post list

This commit is contained in:
2024-03-02 20:01:59 +08:00
parent 178f80c707
commit 3ae72cd9e0
23 changed files with 314 additions and 65 deletions

View File

@@ -0,0 +1,56 @@
import Cookie from "universal-cookie"
import { defineStore } from "pinia"
import { ref } from "vue"
import { request } from "@/scripts/request"
export interface Userinfo {
isReady: boolean
isLoggedIn: boolean
displayName: string
data: any
}
const defaultUserinfo: Userinfo = {
isReady: false,
isLoggedIn: false,
displayName: "Citizen",
data: null
}
export function getAtk(): string {
return new Cookie().get("identity_auth_key")
}
export function checkLoggedIn(): boolean {
return new Cookie().get("identity_auth_key")
}
export const useUserinfo = defineStore("userinfo", () => {
const userinfo = ref(defaultUserinfo)
const isReady = ref(false)
async function readProfiles() {
if (!checkLoggedIn()) {
isReady.value = true;
}
const res = await request("/api/users/me", {
headers: { "Authorization": `Bearer ${getAtk()}` }
});
if (res.status !== 200) {
return;
}
const data = await res.json();
userinfo.value = {
isReady: true,
isLoggedIn: true,
displayName: data["nick"],
data: data
};
}
return { userinfo, isReady, readProfiles }
})

View File

@@ -0,0 +1,14 @@
import { request } from "@/scripts/request"
import { defineStore } from "pinia"
import { ref } from "vue"
export const useWellKnown = defineStore("well-known", () => {
const wellKnown = ref({})
async function readWellKnown() {
const res = await request("/.well-known")
wellKnown.value = await res.json()
}
return { wellKnown, readWellKnown }
})