Download stores/user.ts from binhugg4/web: direct link, hf CLI and curl.
- Browser
- Download file 716 Bytes
-
https://huggingface.co/spaces/binhugg4/web/resolve/main/stores/user.ts
- Command line
-
hf download hf://spaces/binhugg4/web/stores/user.ts
-
curl -L -o user.ts https://huggingface.co/spaces/binhugg4/web/resolve/main/stores/user.ts
716 Bytes
| export const useUserStore = defineStore("user", () => { | |
| const token = useCookie<string | null>("binv_token", { maxAge: 60 * 60 * 24 * 7 }) | |
| const userInfo = ref<{ | |
| id: number | |
| username: string | null | |
| nickname: string | null | |
| avatar: string | null | |
| email: string | null | |
| } | null>(null) | |
| const isLoggedIn = computed(() => !!token.value) | |
| async function fetchProfile() { | |
| if (!token.value) return | |
| try { | |
| const { get } = useApi() | |
| userInfo.value = await get<any>("/user/auth/profile") | |
| } catch { | |
| userInfo.value = null | |
| } | |
| } | |
| function logout() { | |
| token.value = null | |
| userInfo.value = null | |
| } | |
| return { token, userInfo, isLoggedIn, fetchProfile, logout } | |
| }) |