Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement HTMX integration #5

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"require": {
"xp-forge/handlebars-templates": "^3.1",
"xp-forge/frontend": "^6.0",
"xp-forge/htmx": "^0.1",
"xp-forge/websockets": "^3.0",
"xp-forge/mongodb": "^2.2",
"xp-forge/redis": "^1.0",
Expand Down
11 changes: 11 additions & 0 deletions src/main/handlebars/layout.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,16 @@
{{> content}}
</main>
<script src="/static/vendor.js"></script>
<script type="module">
window.addEventListener('authenticationexpired', e => {
if (confirm('Authentication expired. Do you want to re-authenticate?')) {
window.location.reload();
return;
}
});
</script>
{{#> scripts}}
<!-- Defaults to empty -->
{{/scripts}}
</body>
</html>
4 changes: 2 additions & 2 deletions src/main/php/de/thekid/crews/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use web\Application;
use web\auth\SessionBased;
use web\auth\oauth\{OAuth2Flow, BySecret};
use web\frontend\{Frontend, AssetsFrom, HandlersIn};
use web\frontend\{Frontend, AssetsFrom, HandlersIn, HtmxFlow};
use web\session\InFileSystem;

/** Web frontend */
Expand All @@ -28,7 +28,7 @@ public function routes() {
'/',
$config->readArray('oauth', 'scopes'),
);
$auth= new SessionBased($flow, $sessions, $flow->fetchUser($config->readString('oauth', 'userinfo'))
$auth= new SessionBased(new HtmxFlow($flow), $sessions, $flow->fetchUser($config->readString('oauth', 'userinfo'))
->map(new UserAttributes($config->readSection('user')))
->map(fn($user) => $db->collection('users')
->modify(['handle' => $user['handle']], ['$set' => $user], upsert: true)
Expand Down
Loading