summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/ssr/src/pages/login.astro17
1 files changed, 10 insertions, 7 deletions
diff --git a/examples/ssr/src/pages/login.astro b/examples/ssr/src/pages/login.astro
index 51ad74008..030838a64 100644
--- a/examples/ssr/src/pages/login.astro
+++ b/examples/ssr/src/pages/login.astro
@@ -14,10 +14,10 @@ import Container from '../components/Container.astro';
<script type="module" is:inline>
document.addEventListener('DOMContentLoaded', () => {
- console.log('loaded');
- document.querySelector('form').addEventListener('submit', (e) => {
+ const form = document.querySelector('form');
+ if (!form) throw new Error('Form not found');
+ form.addEventListener('submit', (e) => {
e.preventDefault();
- const form = e.target;
const formData = new FormData(form);
const data = Object.fromEntries(formData);
@@ -26,10 +26,13 @@ import Container from '../components/Container.astro';
body: JSON.stringify(data),
})
.then((res) => res.json())
- .then((data) => {
- document.querySelector('#result').innerHTML =
- 'Progressive login was successful! you will be redirected to the store in 3 seconds';
- setTimeout(() => (location.href = '/'), 3000);
+ .then(() => {
+ const result = document.querySelector('#result');
+ if (result) {
+ result.innerHTML =
+ 'Progressive login was successful! you will be redirected to the store in 3 seconds';
+ setTimeout(() => (location.href = '/'), 3000);
+ }
});
});
});