THE LAST ONE BEFORE THE RELEASE

This commit is contained in:
User
2025-02-15 17:41:30 +03:00
parent 646f926c8f
commit a8d15c56f3
242 changed files with 1314 additions and 8683 deletions

View File

@@ -1,6 +1,7 @@
"use client"
import React, { createContext, useContext, useState } from 'react'
import type React from "react"
import { createContext, useContext, useState, useEffect } from "react"
type AuthContextType = {
isLoggedIn: boolean
@@ -13,7 +14,7 @@ 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')
throw new Error("useAuth must be used within an AuthProvider")
}
return context
}
@@ -21,13 +22,23 @@ export const useAuth = () => {
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [isLoggedIn, setIsLoggedIn] = useState(false)
const login = () => setIsLoggedIn(true)
const logout = () => setIsLoggedIn(false)
useEffect(() => {
const storedLoginState = localStorage.getItem("isLoggedIn")
if (storedLoginState === "true") {
setIsLoggedIn(true)
}
}, [])
return (
<AuthContext.Provider value={{ isLoggedIn, login, logout }}>
{children}
</AuthContext.Provider>
)
const login = () => {
setIsLoggedIn(true)
localStorage.setItem("isLoggedIn", "true")
}
const logout = () => {
setIsLoggedIn(false)
localStorage.removeItem("isLoggedIn")
}
return <AuthContext.Provider value={{ isLoggedIn, login, logout }}>{children}</AuthContext.Provider>
}