This repository has been archived on 2025-07-07. You can view files and clone it, but cannot push or open issues or pull requests.
Files
eternos/frontend/style/contexts/auth-context.tsx

34 lines
789 B
TypeScript

"use client"
import React, { createContext, useContext, useState } from 'react'
type AuthContextType = {
isLoggedIn: boolean
login: () => void
logout: () => void
}
const AuthContext = createContext<AuthContextType | undefined>(undefined)
export const useAuth = () => {
const context = useContext(AuthContext)
if (!context) {
throw new Error('useAuth must be used within an AuthProvider')
}
return context
}
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [isLoggedIn, setIsLoggedIn] = useState(false)
const login = () => setIsLoggedIn(true)
const logout = () => setIsLoggedIn(false)
return (
<AuthContext.Provider value={{ isLoggedIn, login, logout }}>
{children}
</AuthContext.Provider>
)
}