Fixed options for templates

This commit is contained in:
Zvonimir Sabljic
2025-01-10 08:35:27 +01:00
parent fb423e3501
commit 3c9d026c83
5 changed files with 17 additions and 11 deletions

View File

@@ -13,7 +13,7 @@ When thinking about the scope of a single task, here are the components that nee
**IMPORTANT: order of tasks**
The tasks you create **MUST** be in the order that they should be implemented. When CRUD operations need to be implemented, first implement the Create operation, then Read, Update, and Delete.
{% if state.has_frontend() and not state.is_feature() and (state.user_options|default({})).get('auth', True) %}
{% if state.has_frontend() and not state.is_feature() and (state.options|default({})).get('auth', True) %}
**IMPORTANT**
If you are working on the Epic #1 that needs to implement the authentication system. The first task **MUST** be to remove the mocked data for authentication (register and login). After that, add any custom authentication requirements like different roles, different user data, etc.
{% endif %}

View File

@@ -52,7 +52,7 @@ class StateManager:
self.blockDb = False
self.git_available = False
self.git_used = False
self.user_options = {}
self.options = {}
@asynccontextmanager
async def db_blocker(self):

View File

@@ -20,6 +20,9 @@ class NoOptions(BaseModel):
Options class for templates that do not require any options.
"""
class Config:
extra = "allow"
pass

View File

@@ -12,10 +12,8 @@ function App() {
<ThemeProvider defaultTheme="light" storageKey="ui-theme">
<Router>
<Routes>
{% if options.auth %}
<Route path="/login" element={<Login />} />
<Route path="/register" element={<Register />} />
{% endif %}
<Route path="/" element={<ProtectedRoute> <Layout /> </ProtectedRoute>} />
</Routes>
</Router>

View File

@@ -1,30 +1,35 @@
{% raw %}
import { Bell{% if options.auth %}, LogOut{% endif %} } from "lucide-react"
import { Bell{% endraw %}{% if options.auth %}, LogOut{% endif %}{% raw %} } from "lucide-react"
import { Button } from "./ui/button"
import { ThemeToggle } from "./ui/theme-toggle"
import { useAuth } from "@/contexts/AuthContext"
import { useNavigate } from "react-router-dom"
export function Header() {{% if options.auth %}
const { logout } = useAuth(){% endif %}
export function Header() {
{% endraw %}
{% if options.auth %}
const { logout } = useAuth()
{% endif %}
const navigate = useNavigate()
{% if options.auth %}
const handleLogout = () => {
logout()
navigate("/login")
}{% endif %}
}
{% endif %}
return (
<header className="fixed top-0 z-50 w-full border-b bg-background/80 backdrop-blur-sm">
<div className="flex h-16 items-center justify-between px-6">
<div className="text-xl font-bold">Home</div>
<div className="flex items-center gap-4">
<ThemeToggle />{% if options.auth %}
<ThemeToggle />
{% if options.auth %}
<Button variant="ghost" size="icon" onClick={handleLogout}>
<LogOut className="h-5 w-5" />
</Button>{% endif %}
</Button>
{% endif %}
</div>
</div>
</header>
)
}
{% endraw %}