Initial commit: FunConnect project with server, relay, client and admin panel

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-02-24 20:56:36 +08:00
parent eb6e901440
commit b6891483ae
167 changed files with 16147 additions and 106 deletions

View File

@@ -0,0 +1,45 @@
import { create } from 'zustand'
import { persist, createJSONStorage } from 'zustand/middleware'
interface AuthState {
token: string | null
isAuthenticated: boolean
login: (username: string, password: string) => Promise<boolean>
logout: () => void
}
export const useAuthStore = create<AuthState>()(
persist(
(set) => ({
token: null,
isAuthenticated: false,
login: async (username: string, password: string) => {
try {
const res = await fetch('/api/v1/admin/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password }),
})
if (!res.ok) {
return false
}
const data = await res.json()
set({ token: data.token, isAuthenticated: true })
return true
} catch {
return false
}
},
logout: () => {
set({ token: null, isAuthenticated: false })
},
}),
{
name: 'funmc-admin-auth',
}
)
)