app/resources/views/components/layouts/guest.blade.php

82 lines
3.2 KiB
PHP
Raw Normal View History

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Dish Planner') }}</title>
<!-- Scripts -->
@vite(['resources/css/app.css', 'resources/js/app.js'])
@livewireStyles
</head>
<body class="font-sans antialiased bg-gray-600 text-gray-100">
2026-01-04 03:58:47 +01:00
<div class="min-h-screen flex flex-col items-center px-4 py-8">
<!-- Logo -->
<div class="w-full max-w-xs mb-8">
<img src="{{ asset('images/logo-with-text.png') }}" alt="Dish Planner" class="w-full">
</div>
2026-01-04 03:58:47 +01:00
<!-- Login box -->
<div class="w-full max-w-sm">
<x-card>
@yield('content')
</x-card>
</div>
</div>
@livewireScripts
{{-- CSRF Token Auto-Refresh for Livewire --}}
<script>
// Handle CSRF token expiration gracefully
Livewire.hook("request", ({ fail }) => {
fail(async ({ status, preventDefault, retry }) => {
if (status === 419) {
// Prevent the default error handling
preventDefault();
try {
// Fetch a new CSRF token
const response = await fetch("/refresh-csrf", {
method: "GET",
headers: {
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest"
},
credentials: "same-origin",
});
if (response.ok) {
const data = await response.json();
const newToken = data.token;
// Update the CSRF token in the meta tag
const csrfMeta = document.querySelector("meta[name='csrf-token']");
if (csrfMeta) {
csrfMeta.setAttribute("content", newToken);
}
// Update Livewire's CSRF token
if (window.Livewire && Livewire.csrfToken) {
Livewire.csrfToken = newToken;
}
// Retry the original request with the new token
retry();
} else {
console.error('Failed to refresh CSRF token');
// For guest layout, just retry once more or show error
window.location.reload();
}
} catch (error) {
console.error('Failed to refresh CSRF token:', error);
window.location.reload();
}
}
});
});
</script>
</body>
</html>