mirror of
https://github.com/Myzel394/kleckrelay-website.git
synced 2025-06-20 00:05:26 +02:00
38 lines
770 B
TypeScript
38 lines
770 B
TypeScript
import {createContext} from "react"
|
|
|
|
import {User} from "~/server-types"
|
|
|
|
interface AuthContextTypeBase {
|
|
user: User | null
|
|
isAuthenticated: boolean
|
|
login: (user: User, callback: () => void) => Promise<void>
|
|
logout: () => void
|
|
}
|
|
|
|
interface AuthContextTypeAuthenticated {
|
|
user: User
|
|
isAuthenticated: true
|
|
}
|
|
|
|
interface AuthContextTypeUnauthenticated {
|
|
user: null
|
|
isAuthenticated: false
|
|
}
|
|
|
|
export type AuthContextType =
|
|
| AuthContextTypeBase
|
|
| (AuthContextTypeAuthenticated & AuthContextTypeUnauthenticated)
|
|
|
|
const AuthContext = createContext<AuthContextType>({
|
|
user: null,
|
|
isAuthenticated: false,
|
|
login: () => {
|
|
throw new Error("login() not implemented")
|
|
},
|
|
logout: () => {
|
|
throw new Error("logout() not implemented")
|
|
},
|
|
})
|
|
|
|
export default AuthContext
|