User sign in

This commit is contained in:
2024-03-28 20:44:13 +08:00
parent 3a1cf006f4
commit 96526da432
33 changed files with 750 additions and 34 deletions

View File

@@ -19,10 +19,10 @@ export const useRealms = defineStore("realms", () => {
const available = ref<any[]>([])
async function list() {
if (!checkLoggedIn()) return
if (!(await checkLoggedIn())) return
const res = await request("interactive", "/api/realms/me/available", {
headers: { Authorization: `Bearer ${getAtk()}` }
headers: { Authorization: `Bearer ${await getAtk()}` }
})
if (res.status !== 200) {
throw new Error(await res.text())

View File

@@ -1,7 +1,7 @@
import Cookie from "universal-cookie"
import { defineStore } from "pinia"
import { ref } from "vue"
import { request } from "@/scripts/request"
import { Preferences } from "@capacitor/preferences"
export interface Userinfo {
isReady: boolean
@@ -17,12 +17,12 @@ const defaultUserinfo: Userinfo = {
data: null
}
export function getAtk(): string {
return new Cookie().get("identity_auth_key")
export async function getAtk() {
return (await Preferences.get({ key: "identity.access_token" })).value
}
export function checkLoggedIn(): boolean {
return new Cookie().get("identity_auth_key")
export async function checkLoggedIn(): boolean {
return (await Preferences.get({ key: "identity.access_token" })).value != null
}
export const useUserinfo = defineStore("userinfo", () => {
@@ -30,12 +30,12 @@ export const useUserinfo = defineStore("userinfo", () => {
const isReady = ref(false)
async function readProfiles() {
if (!checkLoggedIn()) {
if (!(await checkLoggedIn())) {
isReady.value = true
}
const res = await request("interactive", "/api/users/me", {
headers: { Authorization: `Bearer ${getAtk()}` }
const res = await request("identity", "/api/users/me", {
headers: { Authorization: `Bearer ${await getAtk()}` }
})
if (res.status !== 200) {