Skip to content

Commit

Permalink
Merge pull request #5 from thekid/feature/htmx
Browse files Browse the repository at this point in the history
Implement HTMX integration
  • Loading branch information
thekid authored Jan 28, 2024
2 parents 72f5d5c + 094e2b1 commit ff4a9bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
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

0 comments on commit ff4a9bf

Please sign in to comment.