[rewrite] Added shadcn ui to frontend and slightly tweaked backend

This commit is contained in:
Thastertyn committed 2025-02-20 15:16:06 +01:00
1 parent 4c8817e853
commit 6e9334ba0e
202 files changed
+19385 -15424

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
import Cookies from 'js-cookie'
import { create } from 'zustand'
const ACCESS_TOKEN = 'thisisjustarandomstring'
interface AuthUser {
accountNo: string
email: string
role: string[]
exp: number
}
interface AuthState {
auth: {
user: AuthUser | null
setUser: (user: AuthUser | null) => void
accessToken: string
setAccessToken: (accessToken: string) => void
resetAccessToken: () => void
reset: () => void
}
}
export const useAuthStore = create<AuthState>()((set) => {
const cookieState = Cookies.get(ACCESS_TOKEN)
const initToken = cookieState ? JSON.parse(cookieState) : ''
return {
auth: {
user: null,
setUser: (user) =>
set((state) => ({ ...state, auth: { ...state.auth, user } })),
accessToken: initToken,
setAccessToken: (accessToken) =>
set((state) => {
Cookies.set(ACCESS_TOKEN, JSON.stringify(accessToken))
return { ...state, auth: { ...state.auth, accessToken } }
}),
resetAccessToken: () =>
set((state) => {
Cookies.remove(ACCESS_TOKEN)
return { ...state, auth: { ...state.auth, accessToken: '' } }
}),
reset: () =>
set((state) => {
Cookies.remove(ACCESS_TOKEN)
return {
...state,
auth: { ...state.auth, user: null, accessToken: '' },
}
}),
},
}
})
// export const useAuth = () => useAuthStore((state) => state.auth)