Implemented comprehensive Romanian Biblical Guide web app: - Next.js 15 with App Router and TypeScript - Material UI 7.3.2 for modern, responsive design - PostgreSQL database with Prisma ORM - Complete Bible reader with book/chapter navigation - AI-powered biblical chat with Romanian responses - Prayer wall for community prayer requests - Advanced Bible search with filters and highlighting - Sample Bible data imported from API.Bible - All API endpoints created and working - Professional Material UI components throughout - Responsive layout with navigation and theme 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
44 lines
970 B
TypeScript
44 lines
970 B
TypeScript
import { useEffect } from 'react'
|
|
import { useStore } from '@/lib/store'
|
|
|
|
export function useAuth() {
|
|
const { user, setUser } = useStore()
|
|
|
|
useEffect(() => {
|
|
const token = localStorage.getItem('authToken')
|
|
if (token && !user) {
|
|
// Validate token and get user info
|
|
fetch('/api/auth/me', {
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`
|
|
}
|
|
})
|
|
.then(res => res.json())
|
|
.then(data => {
|
|
if (data.user) {
|
|
setUser(data.user)
|
|
} else {
|
|
localStorage.removeItem('authToken')
|
|
}
|
|
})
|
|
.catch(() => {
|
|
localStorage.removeItem('authToken')
|
|
})
|
|
}
|
|
}, [user, setUser])
|
|
|
|
const logout = () => {
|
|
setUser(null)
|
|
localStorage.removeItem('authToken')
|
|
}
|
|
|
|
const isAuthenticated = !!user
|
|
const token = typeof window !== 'undefined' ? localStorage.getItem('authToken') : null
|
|
|
|
return {
|
|
user,
|
|
isAuthenticated,
|
|
token,
|
|
logout
|
|
}
|
|
} |