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>
This commit is contained in:
48
lib/auth-context.tsx
Normal file
48
lib/auth-context.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
"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>
|
||||
}
|
||||
Reference in New Issue
Block a user