Skip to content

Commit

Permalink
Update component.html
Browse files Browse the repository at this point in the history
  • Loading branch information
blazgocompany authored Aug 22, 2024
1 parent c5b3b70 commit ffe1547
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions pages/login/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,35 @@ <h1>Login</h1>
<button type="submit">Login</button>
</form>
<script>
document.getElementById('loginForm').addEventListener('submit', async (event) => {
event.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;

try {
const response = await fetch('/internal/login.blazgo', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password }),
});

if (response.ok) {
window.location.href = '/'; // Redirect to the main page after login
} else {
alert('Invalid credentials');
}
} catch (error) {
console.error('Error:', error);
}
document.getElementById('loginForm').addEventListener('submit', async (event) => {
event.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;

try {
const response = await fetch('/internal/login.blazgo', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password }),
});

if (response.ok) {
const result = await response.text(); // Assuming the server returns JSON
const sessionId = result; // Extract the session ID from the response

// Set the session ID in cookies
document.cookie = `sessionId=${sessionId}; path=/; secure; samesite=strict`;

// Redirect to the main page after login
window.location.href = '/';
} else {
alert('Invalid credentials');
}
} catch (error) {
console.error('Error:', error);
}
});

</script>
</body>
</html>

0 comments on commit ffe1547

Please sign in to comment.