mirror of
https://github.com/Myzel394/kleckrelay-website.git
synced 2025-06-20 08:15:26 +02:00
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import {createContext} from "react"
|
|
|
|
import {ServerUser, User} from "~/server-types"
|
|
|
|
interface AuthContextTypeBase {
|
|
user: ServerUser | User | null
|
|
isAuthenticated: boolean
|
|
login: (user: ServerUser, callback?: () => void) => Promise<void>
|
|
logout: () => void
|
|
_decryptContent: (content: string) => string
|
|
_encryptContent: (content: string) => string
|
|
_setDecryptionPassword: (decryptionPassword: string) => void
|
|
_updateUser: (user: ServerUser | User) => void
|
|
}
|
|
|
|
interface AuthContextTypeAuthenticated {
|
|
user: ServerUser
|
|
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")
|
|
},
|
|
_decryptContent: () => {
|
|
throw new Error("_decryptContent() not implemented")
|
|
},
|
|
_encryptContent: () => {
|
|
throw new Error("_encryptContent() not implemented")
|
|
},
|
|
_setDecryptionPassword: () => {
|
|
throw new Error("_setMasterDecryptionPassword() not implemented")
|
|
},
|
|
_updateUser: () => {
|
|
throw new Error("_updateUser() not implemented")
|
|
},
|
|
})
|
|
|
|
export default AuthContext
|