Rollback server side set cookie

This commit is contained in:
LittleSheep 2024-08-13 00:52:48 +08:00
parent 1130e6a574
commit 14f2bc0ee6
4 changed files with 12 additions and 6 deletions

View File

@ -131,7 +131,6 @@ async function readTickets({ page, itemsPerPage }: { page?: number; itemsPerPage
}),
{
headers: { Authorization: `Bearer ${useAtk().value}` },
credentials: "include",
},
)
if (res.status !== 200) {
@ -157,7 +156,6 @@ async function readEvents({ page, itemsPerPage }: { page?: number; itemsPerPage?
}),
{
headers: { Authorization: `Bearer ${useAtk().value}` },
credentials: "include",
},
)
if (res.status !== 200) {
@ -177,7 +175,6 @@ async function killTicket(item: any) {
const res = await fetch(`${config.public.solarNetworkApi}/cgi/auth/users/me/tickets/${item.id}`, {
method: "DELETE",
headers: { Authorization: `Bearer ${useAtk().value}` },
credentials: "include",
})
if (res.status !== 200) {
error.value = await res.text()

View File

@ -16,6 +16,7 @@
<script setup lang="ts">
import { onMounted, ref } from "vue"
import { useRoute, useRouter } from "vue-router"
import { setTokenSet } from "~/stores/userinfo"
const config = useRuntimeConfig()
@ -51,6 +52,8 @@ async function getToken(tk: string) {
error.value = err
throw new Error(err)
} else {
const out = await res.json()
setTokenSet(out["access_token"], out["refresh_token"])
error.value = null
}
}

View File

@ -88,7 +88,6 @@ const panel = ref("confirm")
async function tryAuthorize() {
const res = await fetch(`${config.public.solarNetworkApi}/cgi/auth/auth/o/authorize` + window.location.search, {
headers: { Authorization: `Bearer ${useAtk().value}` },
credentials: "include",
})
if (res.status !== 200) {
@ -121,7 +120,6 @@ async function approve() {
const res = await fetch(`${config.public.solarNetworkApi}/cgi/auth/auth/o/authorize` + window.location.search, {
method: "POST",
headers: { Authorization: `Bearer ${useAtk().value}` },
credentials: "include",
})
if (res.status !== 200) {

View File

@ -17,6 +17,15 @@ export function useAtk() {
return useCookie("__hydrogen_atk", { watch: "shallow" })
}
export function useRtk() {
return useCookie("__hydrogen_rtk", { watch: "shallow" })
}
export function setTokenSet(atk: string, rtk: string) {
useAtk().value = atk
useRtk().value = rtk
}
export function useLoggedInState() {
return computed(() => useAtk().value != null)
}
@ -34,7 +43,6 @@ export const useUserinfo = defineStore("userinfo", () => {
const res = await fetch(`${config.public.solarNetworkApi}/cgi/auth/users/me`, {
headers: { Authorization: `Bearer ${useAtk().value}` },
credentials: "include",
})
if (res.status !== 200) {