Files
asaas-checkout/lib/auth-context.tsx
Felipe Carvalho 038ce3f556 feat: initial commit — asaas-checkout template white-label
Template genérico de checkout com ASAAS, parametrizado via env vars.
Inclui fluxo completo: checkout → pedido → polling → webhook → admin.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 06:40:41 +02:00

49 lines
1.3 KiB
TypeScript

"use client"
import type React from "react"
import { createContext, useContext, useState, useEffect } from "react"
interface AuthContextType {
isLoggedIn: boolean
login: (username: string, password: string) => Promise<boolean>
logout: () => void
}
const AuthContext = createContext<AuthContextType>({
isLoggedIn: false,
login: async () => false,
logout: () => {},
})
export const useAuth = () => useContext(AuthContext)
export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
const [isLoggedIn, setIsLoggedIn] = useState(false)
useEffect(() => {
const token = localStorage.getItem("isLoggedIn")
if (token === "true") {
setIsLoggedIn(true)
}
}, [])
const login = async (username: string, password: string) => {
const adminUser = process.env.NEXT_PUBLIC_ADMIN_USER ?? "admin"
const adminPass = process.env.NEXT_PUBLIC_ADMIN_PASSWORD ?? "admin"
if (username === adminUser && password === adminPass) {
localStorage.setItem("isLoggedIn", "true")
setIsLoggedIn(true)
return true
}
return false
}
const logout = () => {
localStorage.removeItem("isLoggedIn")
setIsLoggedIn(false)
}
return <AuthContext.Provider value={{ isLoggedIn, login, logout }}>{children}</AuthContext.Provider>
}